2 Jul, 2019

Understanding The Drawing Representation

CATIA’s data model is structured around two main object types: Physical Products (Parts and Products) that hold information pertaining to structure, and Representations that hold information relating to descriptions– whether 3D geometry as in Shapes and Skeletons, or Knowledgeware features as in Knowledge Engineering Specifications, or 2D view drawings as in Drawings. An overview of CATIA’s data model was described in previous posts. In this post, I’ll focus on the Drawing Representation.

The Drawing Data Model

CATIA Drawings are Representations whose V_discipline attribute value is "Drafting". Here is an overview of relationships found above and below the Drawing Representationobject. Note that there are two types of Representations. Aggregated and Shared.

Aggregated vs Shared

The Aggregated type is created by default when a drawing (or a shape) is inserted as new inside a VPMReference. If a drawing is created by the c: new content command or the + sign, it will be created as a Shared representation in its own new tab (Editor).

One difference is that Aggregated representations have no PLM state and revision of their own; they follow their parent VPMReference. Shared representations, however, have their own PLM state and revision, independent of their position in the tree (noticed I didn’t say "parent in the tree").

Another difference is that Aggregated representations do not have a notion of Instance (and no Instance tab in their Properties Window). They can only exist inside one VPMReference. Shared representations can have multiple instances under any node in an assembly. They do not have a designated Parent.

Finally, it is possible to convert an Aggregated representation to Shared, but not the opposite; and once converted to Shared, it can not be changed back to Aggregated.

The graphical notation difference in CATIA’s tree is as follows: Top is Shared (with an arrow), bottom is Aggregated.

Data Model

Here is high-level diagram of where the drawing Representation falls in CATIA’s data model:


To quickly test our understanding of the above structure, let’s fire up a Drawing and write some VbScript code:

Here is the code in the above video.

Dim root As DrawingRoot
set root = CATIA.ActiveEditor.ActiveObject

Dim repRef As VPMRepReference
Set repRef = root.Parent

'Note that this property, Father, will be always null for Shared Representations/drawings. It will only return a VPMReference is the Drawing is Aggregated.'
Dim vpmRef As VPMReference
set vpmRef = repRef.Father

MsgBox "Root is " & root.Name & "VPMRepRef is " & repRef.Name & "VPMRef is " & vpmRef.Name

Navigating Drawing Inner Collections

Getting the collections inside a drawing is easy. Note that all CATIA API collections are 1 based. That is, the first element is at index 1. That said, VBScript arrays and VBA collections, as well as C-Sharp’s [all] data structures are 0 based– the first element is at index 0.

'In VBscript and VBA, we can declare variables without a type'
Dim sheets
Set sheets = drwRoot.Sheets
MsgBox "DrawingRoot has a Sheets collection, whose type is a <" + TypeName( sheets)+ "> that has " + Cstr(sheets.Count) + " nested sheets"

'or we can declare them as Object'
Dim aSheet as object
Set aSheet = sheets.Item(1)

'VBScript objects types are resolved at runtime--when the script is executed.'
MsgBox "Sheet one's name is <" + aSheet.Name + "> and its type is <" + TypeName(aSheet) +">"

Dim views
Set views = aSheet.Views
MsgBox "aSheet has a Views collection, which at least has " + Cstr(views.Count) + " views. The first is the foreground, and the second is the background"

Dim view
Set view = views.Item(1)
MsgBox "The first view is at index 1, and its type is similar to the second view, which is <" + TypeName(view) + ">"

To get the type name of any object in CATScript, VbScript, or VBA; use the TypeName( theObject). This is simialr to EKL’s theObject.PrimaryType.Name and C-Sharp’s TypeDescriptor.GetClassName(theObject).

Adding Sheets

Dim sheets
Set sheets = drwRoot.Sheets

Dim mySheet As DrawingSheet
'add a new sheet and append the number of currently existing sheets +1. Note the CStr method to cast the integer to a string'
sheets.Add( "Sheet " + Cstr(sheets.Count +1))

'Then we set the mySheet variable to the last added item--which is at the index equal to the sheets count'
Set mySheet = sheets.Item( sheets.Count)


The above is a quick overview of the Drawing data model in CATIA. The API for creating and editing drawings is too vast to be covered in a single post. Thus, more posts will be added to focus on specific tasks. Note that I used the dotnet API today since there are very few APIs exposed to EKL at this time.

Tags: , , , , ,

About : Maher Elkhaldi

Maher Elkhaldi is a senior applications engineer at Tesla Motors. He founded the 3DXAutomation blog to help make knowledge of programming CATIA easier to find, and contribute to the open-source community.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.