Transitioning Macros Part 3: Services

December 15, 2023 Iouri Apanovitch

This is Part 3 in this series of transitioning macros from CATIA V5 to the 3DEXPERIENCE (3DX) platform.  In this post we will how talk about the 3DX services.

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

What if you want to program an operation that is not related to the type of content you’re working with? Such as measuring distance, or calculating inertia, or creating a section?

In V5 scripting, you would use either GetWorkbench or GetTechnologicalObject methods, with keywords such as “Inertia”, or “Sections”, or “SPAWorkbench”, etc., which would return you a handle for the object that has all the functions you’re looking for.

But in 3DX, you have to use a “service”.

A Service object in 3DX gives you access to object-independent operations and there are two categories of Services.

Session-level Services

The first category is called Session-level Services. These apply to any type of content, or even when there is no open content on the screen. Here’s the list of the most important session-level Services:

  • PLMNewService: Creates new content
  • PLMOpenService: Opens existing content from the DB
  • PLMPropagateService: Saves modified content to the DB
  • SearchService: Searches the DB for content
  • VisuServices: Works with Windows, Cameras, Viewpoints, etc.

The session-level services belong to the root object (CATIA) and are obtained by calling the GetSessionService method. For example, the following code could be used to get a hold of the PLMNewService:

01: Dim oServ As PLMNewService

02: Set oServ = CATIA.GetSessionService("PLMNewService")

The examples of using the session-level services for working with the PLM database have been presented in Part 2 or this blog post series – just look it up!

Editor-level Services

The second category is called Editor-level Services. Those apply only to specific PLM types, and here’s the list of the most important ones:

  • MeasurableService: Taking distance or other measurements
  • InertiaService: Inertia measurements
  • InterferenceServices: Clash analysis
  • SectionService: Cross-sectioning
  • DrawingService, DrawingGenService: Drawing-related

The editor-level services belong to the Editor object and are obtained by calling the GetService method, with a proper keyword.

Example: Obtaining Coordinates of a Point

As an example, let’s consider using the MeasurableService to obtain coordinates of a point.

The object diagram as well as the measured item types and contexts are shown in Figure 1.

Figure 1

The first step is to get a hold of the MeasurableService for the active Editor:

01: Dim oEditor As Editor

02: Set oEditor = CATIA.ActiveEditor

03: Dim oServ As MeasurableService

04: Set oServ = oEditor.GetService("MeasurableService")

Next, we get the Measurable object for the point we want to measure:

05: Dim oMeasPoint As MeasurablePoint

06: Set oMeasPoint = oMeasurableService.GetMeasurable(<point>, CAAMeasurablePoint)

Now we can measure coordinates in part context:

07: oMeasPoint.SetMeasurableContextType PartContext

08: Dim dX1 As Double: Dim dY1 As Double: Dim dZ1 As Double

09: oMeasPoint.GetPoint dX1, dY1, dZ1

Or in product context:

10: oMeasPoint.SetMeasurableContextType ProductContext

11: oMeasPoint.GetPoint dX1, dY1, dZ1

Example: Measuring Mass and CoG Position

Similarly, the below code could be used to measure the mass and the CoG position for the model in session.

' Editor and Service

                01: Dim oEditor As Editor

                02: Set oEditor = CATIA.ActiveEditor

                03: Dim oServ As InertiaService

                04: Set oServ = oEditor.GetService("InertiaService")

                 ' Inertia object for the active object in session

                05: Dim oInertia As Inertia

                06: Set oInertia = oServ.GetInertiaElement(oEditor.ActiveObject)

                 ' Mass and COG

                07: Dim dMass As Double

                08: dMass = oInertia.GetMass

                09: Dim dX As Double: Dim dY As Double: Dim dZ As Double

                10: oInertia.GetCOGPosition dX, dY, dZ

And that’s all I have for you about the 3DX Services! In my next post, I’ll be explaining the Product Modeler, which is probably the most convoluted subject in 3DX automation.

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 2: Creating, Opening, and Saving Files
Transitioning Macros Part 2: Creating, Opening, and Saving Files

Learn about creating, opening, and saving files when transitioning macros from CATIA V5 to the 3DEXPERIENCE...

Next 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...