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.
Dim partDocument1 As Document
Dim part1 As Part
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
Msgbox "Not a part document! Open in new window."
Learn other VBA macros for CATIA.