How to create a new geometrical set within a CATPart
If you’re going to create new geometry with a CATScript macro in CATIA V5, it is often a good idea to create a brand new geometrical set to place this new geometry. This can be accomplished as a “first step” within your macro code. First, we’ll use On Error Resume Next as our error handling vehicle to insure that the active document is a part document. If not, a message box will display and the macro will quit running. If there are no errors (error=0) then we’ll continue on with the rest of our script. A geometrical set in a CATScript code is a hybrid body. Use the Add() function to insert the new hybrid body and then the Name function to rename it whatever you like. Then, we’ll set that as the in work object (the object with the line under it) this way any additional geometry will be created within this geometrical set. See the complete CATScript below and please note the comments contained within.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | Language="VBSCRIPT" Sub CATMain() Dim partDocument1 As Document Dim part1 As Part 'error handling On Error Resume Next Set partDocument1 = CATIA.ActiveDocument Set part1 = partDocument1.Part If Err.Number=0 Then Dim hybridBodies1 As HybridBodies Set hybridBodies1 = part1.HybridBodies Dim hybridBody2 As HybridBody Set hybridBody2 = hybridBodies1.Add() hybridBody2.Name = "NEW GEOMETRICAL SET" 'sets the newly created geometrical set as the in work object part1.InWorkObject = hybridbody2 part1.Update 'error handling Else Msgbox "Not a part document! Open in new window." End If End Sub |
Learn other VBA macros for CATIA.
First of all: Congrats for this web, it helped me a lot!
Could anybody help me, please?!
I would like to know how can I define the father of my
selection as In work object. In order to insert the new geometry created in the same geoset.
I’m working with a loop so I need it to be done with every Item of the selection.
Thank you very much!
how to just select a geometricalset and then generate many geometricalset under this selected geometricalset,then i don’t need always dim hybridbodies or hybridbody use the catia tree structure
Hi Andy, You can select a geo set using Search by searching for name or type. Or use SelectElement to have a user interactively select the geoset.
Hello Emmett!
Thank you for your cite and book!
I’m programming macros that create main “Geometrical set” and child “Geo. sets” under the main, with my own names. But they cretates after PartBody. And i didn’t find any information how to reorder them before PartBody.
Hello there,
I copied the the program but I’m getting the error saying the Line 3 and column 18 is the error. Can you please suggest me what is the error???
Hello Emmett,
I copied the the program but I’m getting the error saying the Line 3 and column 18 is the error. Can you please suggest me what is the error???
WHich line and what code exactly?
How to change geometrical set using vba ?
Como transformar um subconjunto (product) em Geometrical set