Transitioning Macros Part 5: Part Modeling & Drafting

January 9, 2024 Iouri Apanovitch

Here we go! Part 5 in this series of blog posts, in which we will talk about the Part Modeler and Drafting. Mostly good news here – the Part and the Drafting scripting is very similar to V5.

For reference, here are all of the blogs in this series:
Part 1: Framework
Part 2: Creating, Opening, and Saving Files
Part 3: Services
Part 4: Product Modeler
Part 5: Part Modeling and Drafting
Part 6: Selections
Part 7: Deployment

Part Modeler

The Part, which is the 3D Shape in 3DX, object diagram is shown in Figure 1.

If you notice, the object diagram is pretty much the same as in V5. You’ve got your Bodies collection, HybridBodies collection, Sketches, Factories, and so on. Which means – once you got a hold of the Part object in 3DX, you have a good chance of using your V5 code as-is from there on. And your V5 part modeling scripting skills will very much apply.

Figure 1

Now, the question is – how do you get a hold of the Part object?

If the 3D Shape level is active, as in Figure 2, the ActiveObject property in the Editor is the Part object. So you can use the below code to access the Part.

01: Dim oPart As Part

02: Set oPart = CATIA.ActiveEditor.ActiveObject

Figure 2

However, it’s different if the 3D Part level is active, as in Figure 3 below.

Figure 3

The ActiveObject in this case is VPMRootOccurrence, and you have to get down to the VPMRepReference object, using the Product object diagram (Figure 5 in Part 4 of the series), which is where the Part object resides. The code would look something like below:

01: Dim o3DPart As VPMRootOccurrence

02: Set o3DPart = CATIA.ActiveEditor.ActiveObject          ‘ get the root occurrence

03: Dim oVPMRef As VPMReference

04: Set oVPMRef = o3DPart.ReferenceRootOccurrenceOf()           ‘ get its Reference

05: Dim oRepInstance As VPMRepInstance

06: Set oRepInstance = oVPMRef.RepInstances.Item(1) ‘ get the 1st Representation Instance

07: Dim oRepRef As VPMRepReference

08: Set oRepRef = oRepInstance.ReferenceInstanceOf() ‘ get the Rep Reference

09: Dim oPart As Part

10: Set oPart = oRepRef.GetItem("Part")              ‘ finally, get the Part object


Again, good news here. Drafting scripting in 3DX is very similar to V5, with just a few differences:

  • Creating a new Drawing is different. See Part 2 in this series of blog posts for the how-to
  • DrawingViewGenerativeBehavior object has been replaced with DrawingDefineGenView object.
  • The drawing view properties are now modified using the DrawingGenService service.

The Drafting object diagram is shown in Figure 4.

Figure 4

The DrawingDefineGenView object in 3DX replaces the DrawingViewGenerativeBehavior from V5. Essentially, this is a “factory” that owns methods to create generative views from 3D:

  • DefineFrontView
  • DefineIsometricView
  • DefineProjectionView
  • DefineSectionView
  • DefineStandAloneSection
  • DefineAuxiliaryView
  • DefineCircularDetailView
  • DefinePolygonalDetailView
  • DefineUnfoldedView

The DrawingDefineGenView object is owned by the DrawingViews collection, and can be retrieved using the following code:

01: Dim oDrwRoot As DrawingRoot

02: Set oDrwRoot = CATIA.ActiveEditor.ActiveObject

03: Dim cViews As DrawingViews

04: Set cViews = oDrwRoot.ActiveSheet.Views

05: Dim oGenViewFact As DrawingDefineGenView

06: Set oGenViewFact = cViews.DrawingDefineGenView

Drawing Services

There are two editor-level Drawing services in 3DX:

  • DrawingGenService: Used to modify the generative view properties as well as check the integrity of the drawing links to 3D
  • DrawingService: Used to work with drafting standards

For example, to change view properties such as hidden line mode, or fillet representation, in V5 you would have to use the DrawingViewGenerativeBehavior object. In 3DX, you use the DrawingGenService, like in the code below:

01: Dim oDrwGenService As DrawingGenService

02: Set oDrwGenService = CATIA.ActiveEditor.GetService("CATDrawingGenService")

03: Dim oGenViewProp As DrawingGenViewProperties

04: Set oGenViewProp = oDrwGenService.DrawingGenViewProp

05: oGenViewProp.HiddenLineMode = catHlrModeOn ' this activates the hidden line mode

06: oGenViewProp.FilletRepresentation = catFilletRepSymbolic ' this changes fillet rep

That’s all I have to say about the Part Modeling and Drafting! To summarize, probably you will have to modify your V5 code, but the tweaks should be minor and easy to implement.

We’re nearing the end of our blog series journey, only two posts remaining. In the next post, I’ll be explaining how to work with selections, and the last post will be dedicated to the deployment. 

About the Author

Iouri Apanovitch

Senior Technical Training Engineer<br><br>As a senior member of the Rand 3D team with a doctorate degree in Finite Element Analysis (FEA) and over 35 years of experience, Iouri provides design, consulting, and training services to those in the aerospace, automotive, electronics, and consumer goods industries. Iouri is a seasoned pro in 3D parametric design and prototyping using knowledge-based engineering methods, and has worked on a wide range of projects including BOM automation, CMM points generation, automated 3D annotation creation, and die tooling automation design. He is also a sought-after instructor and holds the designations of both CATIA Certified Professional (Expert level) and CATIA Certified Instructor.

Follow on Linkedin Visit Website More Content by Iouri Apanovitch
Previous Article
Transitioning Macros Part 4: Product Modeler
Transitioning Macros Part 4: Product Modeler

Get an overview of the product modeler in the 3DXEXPERIENCE along with a comparison of how it works in CATI...

Next Article
Transitioning Macros Part 6: Selections
Transitioning Macros Part 6: Selections

Learn about Selections in Part 6 of this blog series on Transitioning Macros from CATIA V5 to 3DEXPERIENCE.