When to use CreateReference

Many CATIA automation functions or methods require parameters of the Reference type. The reference object is designed to unify the use of both exposed in automation objects and non-exposed objects, such as b-rep elements. A reference is made if a method is used as an input parameter. A Reference represents the Reference class, which is created with the CreateReferenceFrom methods of the part object class. The reference is then passed to an object to enable associativity with the referenced object.

For example, you could use the following method to create a new sketch:

Func Add (reference iPLane) As sketch

In the above example using sketch, the new sketch in CATIA might be created on a plane (plane object) or on a planar solid face (planarface object). Because these are two very different objects one option might be to have two functions to create a new sketch – one using plane object as parameter and another using planarface object as a parameter

Instead, the CATIA programmers set one function to create a new sketch that uses a unified parameter of the reference types and then to use methods to convert objects of various types to the Reference type.

To create a new sketch on xy plane:

Dim oRefPLane As Reference

Set oRefPlane = oPart.CreateReferenceFromObject(oPart.OriginElements.PlaneXY)

Dim oSketch1 As Sketch

Set oSketch1 = oBody.Sketches.Add(oRefPlane)

 

reateReferenceFromObject


What CreateReference to Use?

There are four ways to derive a reference:

  1. For geometry: CreateReferenceFromGeometry
  2. For objects: CreateReferenceFromObject
  3. For names: CreateReferenceFromName (string iobjectname) As Reference
  4. For Brep: CreateReferenceFromBRepName (string ilabel, any object icontext) as reference

 

CreateReferenceFromGeometry

CreateReferenceFromGeometry derives a reference from a geometry object such as a wireframe, surface, or solid. Example:

Dim oRef As Reference

Set oRef = MyPart.CreateReferenceFromGeometry(aPoint)

Msgbox oRef.DisplayName

 

CreateReferenceFromObject

CreateReferenceFromObject is used when you have a single object pointing to another object. As an example, here’s how you would create references for objects used as inputs for a join operation:

' Creating a reference for the Fill.1 object

Dim hybridShapeFill1 As HybridShape
Set hybridShapeFill1 = OpenBody1.HybridShapes.Item("Fill.1")

Dim reference1 As Reference
Set reference1 = oPartDocument.Part.CreateReferenceFromObject(hybridShapeFill1)

' Creating a reference for the Extrude.1 object
Dim hybridShapeExtrude1 As HybridShape
Set hybridShapeExtrude1 = OpenBody1.HybridShapes.Item("Extrude.1")

Dim reference2 As Reference
Set reference2 = oPartDocument.Part.CreateReferenceFromObject(hybridShapeExtrude1)

 

As you can see, the Fill and the Extrude surfaces used as input for the Join are converted into references. This operation is required in order to use the objects as input for the Join. In fact, all objects used as input in IDL method interfaces are to be converted as references and passed in creation methods.

 

CreateReferenceFromName

CreateReferenceFromName creates a reference to an object. This is seldom used unless you need a reference that points to nothing (if you need a reference but it won’t be determined until later).

Dim oRef As Reference

Set oRef = myPart.CreateReferenceFromName(“”)

 

 

CreateReferenceFromBrep

A BREP is a boundary representation object such as a point, edge, vertex, or face of a geometric element.  If a reference to part of geometry (or brep) is needed:

 

Dim oRef As Reference

Set oRef=myPart.CreateReferenceFromBRepName(edge, pad)

 

DisplayName

The name of the object referenced by a reference can be determined with the Display Name property: Reference.DisplayName. It returns the name of the referenced object. The name of the referenced object is either the name displayed in the specification tree for a GeometricElement object or a character string defining the reference for a boundary object.  For example, the following returns in StrName the displayable name of reference FirstRef:

StrName = FirstRef.DisplayName

Hopefully this has cleared up some of the confusion about when to use CreateReference. As always, if you have any questions please post them on the forum.

3 Comments

Add a Comment

Your email address will not be published. Required fields are marked *

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