Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

CATIA _ AddNewDatums function 1

romaleee

Mechanical
May 13, 2016
39
Hi guys. I need help please. I got this code chunk that worked fine and did his job and at some point just broke. I don't know what I did to break it and that's why I need your assistance. I got two lines in a sketch and I'm trying to get two connex curves out of it. Something is wrong with my logic and I dont know what. Error that I'm getting is::

1744704951511.png

Model tree:


1744704800412.png


Code:

Code:
Sub CatMain()

'input
Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As Part
Set part1 = partDocument1.Part
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies
Dim hybridBody1, hybridBody2 As HybridBody
Set hybridBody1 = hybridBodies1.Item("GS_Geo")
Set hybridBody2 = hybridBodies1.Item("GS_Uzad")
Dim sketches1 As Sketches
Set sketches1 = hybridBody1.HybridSketches
Dim sketch1 As Sketch
Set sketch1 = sketches1.Item("Sketch_Two_lines")
Dim oRef As Reference
Set oRef = part1.CreateReferenceFromObject(sketch1)
Dim hsF As HybridShapeFactory
Set hsF = part1.HybridShapeFactory
Dim i As Integer
Dim arr

'problem
arr = hsF.AddNewDatums(oRef)
Dim num
num = UBound(arr)

For i = 0 To num
    Set oRef = part1.CreateReferenceFromObject(arr(i))
    Set hSSC = hsF.AddNewSweepCircle(oRef)
    With hSSC
        .Mode = 6
        .SmoothActivity = False
        .GuideDeviationActivity = False
        .SetRadius 1, 2
        .C0VerticesMode = False
        .name = "Sweep_" & i
    End With

    hybridBody2.AppendHybridShape hSSC
Next
part1.Update

End Sub


It probably has something to do with this but I don't know what exactly is meant with this note::

1744705196733.png

@LWolf sorry to tag you but I saw in other thread that you have experience with this function so maybe you know the answer.
Thnx in advance.

Roman
 
Replies continue below

Recommended for you

in the documentation:
"Creates datums from a multi-domain result feature, one datum is created by object domain.
Note; Available only for a shape design feature as input ( not for datum feature )."
it seems that sketch USED to be acceptable, now it is not... So I created a JOIN of the sketch...
and used that instead:

Code:
Sub CatMain()

'input
Dim partDocument1 As partDocument
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As part
Set part1 = partDocument1.part
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies
Dim hybridBody1, hybridBody2 As HybridBody
Set hybridBody1 = hybridBodies1.item("GS_Geo")
Set hybridBody2 = hybridBodies1.item("GS_Uzad")
Dim sketches1 As Sketches
Set sketches1 = hybridBody1.HybridSketches
Dim sketch1 As Sketch
Set sketch1 = sketches1.item("Sketch_Two_lines")
Dim oRef As reference
Set oRef = part1.CreateReferenceFromObject(sketch1)
Dim hsF As HybridShapeFactory
Set hsF = part1.HybridShapeFactory

Dim i As Integer
Dim arr

Dim myJoin As HybridShapeAssemble
Set myJoin = hsF.AddNewJoin(oRef, oRef)
myJoin.RemoveElement 2
myJoin.SetManifold 0
hybridBody1.AppendHybridShape myJoin
part1.UpdateObject myJoin
arr = hsF.AddNewDatums(myJoin)
Set objRef = part1.CreateReferenceFromObject(myJoin)
hsF.DeleteObjectForDatum objRef

Dim num
num = UBound(arr)

For i = 0 To num
    Set oRef = part1.CreateReferenceFromObject(arr(i))
    Set hSSC = hsF.AddNewSweepCircle(oRef)
    With hSSC
        .Mode = 6
        .SmoothActivity = False
        .GuideDeviationActivity = False
        .SetRadius 1, 2
        .C0VerticesMode = False
        .name = "Sweep_" & i
    End With

    hybridBody2.AppendHybridShape hSSC
Next
part1.Update

End Sub
 

Part and Inventory Search

Sponsor