16 Jul, 2019

Understanding The Shape Representation

I explained earlier the Drawing Representation model and touched upon a few notions: Aggregated vs Shared Representations, Collections, and Representation's Root. Let's now take a look at the more complex Shape Representation, and some of the differences between the dotnet and the EKL APIs.

The Shape Data Mode

Shapes are Representations whose V_discipline attribute value is "Design". Similar to Drawing Representations, there are two Shape Representation types: Aggregated and Shared. Also similar is that Shapes have Roots of type Part, as opposed to DrawingRoot in Drawings.

Wireframe elements are HybridShapes and solids are Shapes; while Geometrical Sets are HybridBodies and Bodies are Bodies.

The dotnet API uses a Factory design pattern to create geometric objects. Parts have a HybridShapeFactory and a ShapeFactory. The first creates wireframe elements, and the second creates solids. Here is an overview of relationships found above and below the Shape Representationobject.

wpg_div_wp_graphviz_1

To quickly test our understanding of the above structure, let's take a look:

Here is the code in the above video.

'to get the root of the current editor, first get a PLMProductService object'
Dim service
Set service = CATIA.ActiveEditor.GetService("PLMProductService")

'get the root from the service
Dim root As VPMOccurrence
Set root = service.RootOccurrence

'get the first VPM Occurrence
'here, we're assuming the first one is a Part
Dim PartVPM as VPMoccurrence
Set PartVPM = root.Occurrences.Item(1)

'Get the instance from the Occurrence'
Dim PartInstance As VPMInstance
Set PartInstance = PartVPM.InstanceOccurrenceOf 

'Get the Reference of that Instance'
Dim PartReference As VPMReference
Set PartReference = PartInstance.ReferenceInstanceof

'lets get its V_usage
Dim usage As String
'will be "3DPart"
usage = PartReference.GetAttributeValue("V_usage")

'we exit is value is 3DPart for example..'
If (usage<>"3DPart") Then
     Exit Sub
End If

'let's get the Representations nested inside tha VPMRefernce
'there can be many representations, but typicaly the first one is of type Shape'
Dim RepInstance As VPMRepInstance
Set RepInstance = PartReference.RepInstances.Item(1)


'Get the reference from the instance.'
Dim RepRef As VPMRepReference
Set RepRef = RepInstance.ReferenceInstanceOf

'the discipline of a Shape rep is "Design"'
Dim discipline As String
discipline = RepRef.GetAttributeValue("V_discipline")

'lets get the root of the shape.
Dim ShapeRoot As Part
Set ShapeRoot = RepRef.GetItem("Part")

'now that we are inside the shape root, we can geometrical sets
'this is how to get the first one. We are assuming one already exists'
Dim GeoSet As HybridBody
Set GeoSet = ShapeRoot.HybridBodies.Item(1)

'Let's get the bodies. The first one is NOT always the Part Body.

Dim PartBodyObject As Body
Set PartBodyObject = ShapeRoot.MainBody
MsgBox "Main Body is " + PartBodyObject.Name

'myBody
Dim myBody As Body
Set myBody = ShapeRoot.Bodies.Item(1)
MsgBox "Body at index 1 is " + myBody.Name

'Let's get all solids
Dim solidItem1
Set solidItem1 = myBody.Shapes.Item(1)
MsgBox  "Solid Item Name Is " + solidItem1.Name

'Lets get ordered geo sets
Dim OrderGeoSet As OrderedGeometricalSet
Set OrderGeoSet =ShapeRoot.OrderedGeometricalSets.Item(1)

'let get geometric objects inside a Geoset
Dim GeoItem As HybridShapes 
Set GeoItem = GeoSet.HybridShapes.Item(1)

'let get some parameters
Dim params As Parameters 
Set params = ShapeRoot.Parameters 

'root parameter set
Dim paramRoot 
Set paramRoot = params.RootParameterSet

'parameters under set
Dim dirParams
Set dirParams = paramRoot.DirectParameters 

Dim realParam  As RealParam
Set realParam  =dirParams.Item(1)
MsgBox realParam.Name + " has the value " + Cstr(realParam.Value)

EKL

EKL's API for creating and managing Features in Shapes is quite robust. We can write the above dotnet example with much fewer lines of code. Here is an example for getting all Geometircal Sets under a Shape

//get the root
let assemblyRoot(VPMReference)assemblyRoot = GetEditorRoots("VPMReference").GetItem(1)

//get the shape
let myShape(VPMRepReference)
myShape = root.Find("VPMRepReference", "", true)

//get the geometircal sets
let geoSets(List)
geoSets = myShape.Query("OpenBodyFeature", "")

Closing Remarks

Both APIs, EKL and dotnet, provide access the same data model. However, EKL's API are higher level, and have a few different object-type names from dotnet. For example:

CATIA UI Name Dotnet EKL
Representation VPMRepReference VPMRepReference
Representation Root Part PartFeature
Geometrical Set HybridBody OpenBodyFeature
Body Body BodyFeature
Parameter Parameter ValuePointer
ParameterSet ParameterSet AdvisorParameterSet
Wireframes HybridShapes Wireframes
Solids Shapes Bodies

Dotnet and EKL APIs serve different purposes. The first enables developing automations capable of complex UIs and integration of external services while the second enables integrating, baking, intelligence into CATIA's data models. I would say that dotnet runs along side or on top of CATIA, while EKL runs within. Note that it is possible to create more complex EKL UIs via the KAC role, which also allows writing KML: the Knowledge Modeling Language. KML is an extension to EKL that supports creating Objects and behavior, which will be the focus for the upcoming posts!

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.