thread560-358170
Hello,
I am wondering how can I use a macro to insert a new geometrical set into a user selected(can be preselected or after the macro is started) one no mather how many parent geom. sets does the selected geom. have in the tree structure.
I tried to use the macro code ferdo posted some time ago:
Language="VBSCRIPT"
Sub CATMain()
Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As Part
Set part1 = partDocument1.Part
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies
Dim oInputType(0)
Dim oStatus
Dim oSelection
Set oSelection = CATIA.ActiveDocument.Selection
Dim Message, Style, Title, Response, MyString
Message = ("This macro will a new GS in a selected one." &_
(chr(13)) &_
(chr(13)) &_
" - The active document window must be a CATPart "&_
(chr(13)) &_
(chr(13)) &_
" Do you want to continue ?")
Style = vbYesNo + vbDefaultButton2 'Define buttons.
Title = "Purpose "
Response = MsgBox(Message, Style, Title)
If Response = vbNo Then
Exit Sub
Else
End If
oInputType(0) = "HybridBody"
oStatus = oSelection.SelectElement2(oInputType, "Select a Geometrical Set", True)
If (oStatus = "Cancel") Then
Exit Sub
End If
Set mySelection = oSelection.Item(1).Value
Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Item(mySelection.Name)
part1.InWorkObject = hybridBody1
Dim hybridBodies2 As HybridBodies
Set hybridBodies2 = hybridBody1.HybridBodies
Dim hybridBody3 As HybridBody
Set hybridBody3 = hybridBodies2.Add()
hybridBody3.Name = "NEW_GS"
part1.Update
End Sub
The only problem here is, that the code works only if the selected geom. set is the root(1st.) level and has no parent geom. sets in the tree structure. If I pick any SUBfolder(child geom. set) I get an error.
Please help..
Hello,
I am wondering how can I use a macro to insert a new geometrical set into a user selected(can be preselected or after the macro is started) one no mather how many parent geom. sets does the selected geom. have in the tree structure.
I tried to use the macro code ferdo posted some time ago:
Language="VBSCRIPT"
Sub CATMain()
Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As Part
Set part1 = partDocument1.Part
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies
Dim oInputType(0)
Dim oStatus
Dim oSelection
Set oSelection = CATIA.ActiveDocument.Selection
Dim Message, Style, Title, Response, MyString
Message = ("This macro will a new GS in a selected one." &_
(chr(13)) &_
(chr(13)) &_
" - The active document window must be a CATPart "&_
(chr(13)) &_
(chr(13)) &_
" Do you want to continue ?")
Style = vbYesNo + vbDefaultButton2 'Define buttons.
Title = "Purpose "
Response = MsgBox(Message, Style, Title)
If Response = vbNo Then
Exit Sub
Else
End If
oInputType(0) = "HybridBody"
oStatus = oSelection.SelectElement2(oInputType, "Select a Geometrical Set", True)
If (oStatus = "Cancel") Then
Exit Sub
End If
Set mySelection = oSelection.Item(1).Value
Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Item(mySelection.Name)
part1.InWorkObject = hybridBody1
Dim hybridBodies2 As HybridBodies
Set hybridBodies2 = hybridBody1.HybridBodies
Dim hybridBody3 As HybridBody
Set hybridBody3 = hybridBodies2.Add()
hybridBody3.Name = "NEW_GS"
part1.Update
End Sub
The only problem here is, that the code works only if the selected geom. set is the root(1st.) level and has no parent geom. sets in the tree structure. If I pick any SUBfolder(child geom. set) I get an error.
Please help..