Dim CATIA As Application Set CATIA = GetObject(, "CATIA.Application") ' Attach to running CATIA ' Or start a new session Set CATIA = CreateObject("CATIA.Application") CATIA.Visible = True Application ├─ Documents (Collection) │ ├─ PartDocument (Part) │ │ └─ Part (body, shapes, parameters) │ ├─ ProductDocument (Assembly) │ │ └─ Product (BOM, instances) │ └─ DrawingDocument (2D) └─ Windows, Editors, Selection 4.3 Typical Code Pattern – Get Active Document Dim activeDoc As Document Set activeDoc = CATIA.ActiveDocument If activeDoc Is Nothing Then MsgBox "No document open" Exit Sub End If 5. Practical Automation Examples 5.1 Create a New Part & Add a Pad (Extrude) Sub CreatePartWithPad() Dim partDoc As PartDocument Set partDoc = CATIA.Documents.Add("Part") Dim part1 As Part Set part1 = partDoc.Part
' In UserForm1 with TextBox1, CommandButton1 Private Sub CommandButton1_Click() GlobalHeight = CDbl(TextBox1.Text) Unload Me End Sub ' In main module Public GlobalHeight As Double dassault systemes vba 7.1
' Your automation logic here ' ...
' Create sketch on XY plane Dim originElements As OriginElements Set originElements = part1.OriginElements Dim xyPlane As Reference Set xyPlane = originElements.PlaneXY Dim CATIA As Application Set CATIA = GetObject(, "CATIA
' Get hybrid body or main shape factory Dim bodies As Bodies Set bodies = part1.Bodies Dim mainBody As Body Set mainBody = bodies.Item("PartBody") 20) ' radius 20mm
' Access parameters collection Dim params As Parameters Set params = part.Parameters
' Create a circle (Factory2D methods) Dim circleCenter As Point2D Set circleCenter = sketch.Factory2D.AddPoint(0, 0) Dim circle As Circle2D Set circle = sketch.Factory2D.AddCircle(0, 0, 20) ' radius 20mm