Transitioning Macros Part 2: Creating, Opening, and Saving Files

December 14, 2023 Iouri Apanovitch

Welcome back! This is Part 2 in this series of blog posts, and here I will explain how to work with the 3DEXPERIENCE (3DX) database content.

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

First of all, Dassault doesn’t like to use the word “file” when we talk about 3DX. As you might very well be aware, all of the 3DX content is stored in the DB, and each and every item in that DB is now called a “PLM Entity”. (Mind you, in the end there’s a file for every item in the DB, stored somewhere on a server.) Still, from here on, we will use the words “PLM entity” or “PLM object” for every item in that DB.

This is probably one of the biggest differences between V5 and 3DX.

Document-based vs. DB-based

V5 is document-based. When you see a model on your screen in V5, it’s represented by two things – the Document object and the Window object. When you open or save a model in V5, CATIA actually either reads or saves a file.

Figure 1

What you see on the 3DX screen is also represented by two things, but now it’s the Editor object and the Window object. The Window object performs the same function as in V5, which is displaying the model on the screen. The Editor object’s role, however, is that of the “controller” for the model’s content. I.e., it holds the current app and maintains the list of all the commands that can be launched from the app.

The Editor has a property ActiveObject, which is the object that you see on the screen. To get a hold of the active object, you could use the following commands in VBA, and from there on work with it.

                01: Dim oActiveObj As AnyObject

                02: Set oActiveObj = CATIA.ActiveEditor.ActiveObject

The content object corresponds to a PLM Entity in the DB, which is represented by a meta-data card and a storage file. Which creates an “extra layer” between 3DX session and the files in the DB. To get the file, the system first reads the meta-data, which tells where exactly the file is located.

Figure 2

In 3DX you can’t just “open” or “save” the model. You have to ask a 3DX “service” to do it for you.

I’ll be discussing in detail the 3DX “services” in part 3 of the series, so for now we’ll keep it simple.

Searching and Opening from the DB

To bring a model into 3DX session, you must search for it first (SearchService), then open it (PLMOpenService). The VBA code would look something like this:

' Get the SearchService object and create search query

                01: Dim oSearchService As SearchService

                02: Set oSearchService = CATIA.GetSessionService("Search")

                03: Dim oDBSearch As DatabaseSearch

                04: Set oDBSearch = oSearchService.DatabaseSearch

                05: oDBSearch.BaseType = "VPMReference“                                       ‘ searches for a PhysicalProduct

                06: oDBSearch.AddEasyCriteria "V_Name", "<model_title>"      ‘ searches using the Title

' Launch the search

                07: oSearchService.Search

' Retrieve the list of found entities

                08: Dim cPLMEntities As PLMEntities

                09: Set cPLMEntities = oDBSearch.Results

' Get the PLMOpen service & open the first found entity

 10: Dim oPLMOpenService As PLMOpenService

 11: Set oPLMOpenService = CATIA.GetSessionService("PLMOpenService")

12: Dim oEditor As Editor

13: oPLMOpenService.PLMOpen cPLMEntities.Item(1), oEditor

Saving to the DB

To save the current model in the DB, you would have to use the PLMPropagateService. The VBA code would look something like this:

' Get the PropagateService object

                01: Dim oSaveService As PLMPropagateService

                02: Set oSaveService = CATIA.GetSessionService("PLMPropagateService")

 ' Save to DB (only saves content of the Active Editor!)

                03: oSaveService.PLMPropagate

Creating new Content

Now, to create new content, you would have to use yet another Service – PLMNewService.

01: Dim oServ As PLMNewService

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

03: Dim oEditor As Editor

04: oServ.PLMCreate “<content_type>”, oEditor

The <content_type> string can have the following values:

  • “Drawing”: Creates a Drawing
  • “3DShape”: Creates a 3D Shape
  • “3DPart”: Creates a 3D Part
  • “VPMReference”: Creates a Physical Product

Here’s the bad news – creating a new 3D Part or a Physical Product from a macro requires a special license, either VMX or E70. Without the license, you can create either a Drawing or a 3D Shape only. Typically, most companies don’t have this license, which means – don’t expect to be able to create a new 3D Part or a Physical Product using scripting!

That’s it for now. In my next post, we’ll be talking about various 3DX “services”, so stay tuned.

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 from CATIA V5 to the 3DEXPERIENCE- Part 1: Framework
Transitioning Macros from CATIA V5 to the 3DEXPERIENCE- Part 1: Framework

Learn how to transition macros from CATIA V5 to the 3DEXPERIENCE in the first blog in this series.

Next Article
Transitioning Macros Part 3: Services
Transitioning Macros Part 3: Services

What if you want to program an operation that is not related to the type of content you’re working with? In...