Insert a new geom.set into an exisiting user selected geometrical set
Insert a new geom.set into an exisiting user selected geometrical set
(OP)
thread560-358170: Catia Macro - Add geometrical set.
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..






RE: Insert a new geom.set into an exisiting user selected geometrical set
Please take a look at the code below (how are set hybridBodies), I hope you will understand why is not working...
CODE --> CATScript
Option Explicit Dim oCATIA As Application Sub CATMain() Set oCATIA = CATIA Dim oDoc As PartDocument Set oDoc = oCATIA.ActiveDocument Dim opart1 As Part Set opart1 = oDoc.Part '----------------------------------------------------------------- Dim hybridBodies1 As HybridBodies Set hybridBodies1 = opart1.HybridBodies Dim hybridBody1 As HybridBody Set hybridBody1 = hybridBodies1.Add() hybridBody1.Name = "Level_1" opart1.UpdateObject hybridBody1 '----------------------------------------------------------------- Dim hybridBodies2 As HybridBodies Set hybridBodies2 = hybridBody1.HybridBodies Dim hybridBody2 As HybridBody Set hybridBody2 = hybridBodies2.Add() hybridBody2.Name = "Level_2" opart1.UpdateObject hybridBody2 '----------------------------------------------------------------- Dim hybridBodies3 As HybridBodies Set hybridBodies3 = hybridBody2.HybridBodies Dim hybridBody3 As HybridBody Set hybridBody3 = hybridBodies3.Add() hybridBody3.Name = "Level_3.1" opart1.UpdateObject hybridBody3 '------------------------------- Dim hybridBodies4 As HybridBodies Set hybridBodies4 = hybridBody2.HybridBodies Dim hybridBody4 As HybridBody Set hybridBody4 = hybridBodies4.Add() hybridBody4.Name = "Level_3.2" opart1.UpdateObject hybridBody4 '-------------------------------- Dim hybridBodies5 As HybridBodies Set hybridBodies5 = hybridBody2.HybridBodies Dim hybridBody5 As HybridBody Set hybridBody5 = hybridBodies5.Add() hybridBody5.Name = "Level_3.3" opart1.UpdateObject hybridBody5 End SubRegards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: Insert a new geom.set into an exisiting user selected geometrical set
The line sets and defines your selection :
Set mySelection = oSelection.Item(1).Value
Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Item(mySelection.Name)
part1.InWorkObject = hybridBody1
So why doesn't the the first made geom. set just make itself inside the selection(the parent) and go threw there on?
Where should the initial code be changed...
Sorry if the questions are noob like, I have just started to learn about macros and I have some issues and problems to overcome still. So for any help I will be most grateful.