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.