Share

Proxies

Introduction to proxies

For the Autodesk Inventor user, the concept of proxy files relates to the use of AutoCAD files in the Autodesk Inventor environment. Proxies in the API context mean something different entirely.

An object proxy is a reference to an object through a particular occurrence. Think of it as a pairing with its respective native object, but returns context-specific data.

An example is a face of a part within an assembly. When this face is queried through the API, what do the results mean - are coordinates returned in the context of the assembly, or the native part? What if the part is inserted into the assembly multiple times; how is a particular instance of the face identified? A key purpose of proxies is to provide answers to these questions. In this case, the proxy of the face object performs the necessary transformations to provide point data in the required context, and also provides information about which occurrence the face is associated with.

The purpose of proxies

To the user, the notion of proxies is transparent. When a user selects a part through the Autodesk Inventor user interface, conceptually the part is in the assembly. It doesn't matter to users that they are working with a proxy that is presenting coordinates and faces and so on in the assembly context and not in the context of the referenced part. But developers need to obtain data specifically in the part or assembly context. There is no geometry in the assembly, only a proxy that is performing the required transformations based on the position of the part within the assembly.


Note: The idea of proxies can be extended to cover the ComponentOccurrence object (the concept is very similar). Consider nested assemblies, or subassemblies, where the level of nesting is three or more levels. An occurrence can be an instance of an assembly definition, not just a part definition. At the top level (the instance), this occurrence is a ComponentOccurrence object as expected, but at other levels these occurrences are represented by ComponentOccurrenceProxy objects.

There is no object model diagram for proxies. Proxies are present for anything that is available for selection in an assembly context, including constraints, features, faces, edges, loops, sketches, profiles, and work features.

Working with proxies through the API

Object proxies are paired with their respective native objects. In fact, proxies are derived from their native objects, and so have common methods and properties. However, an object proxy is a reference to an object through a particular occurrence. In other words, it's a reference to the native object through the occurrence path. This path is potentially long when working with deeply nested subassemblies, so there are means to traverse this path.

Proxy objects have two additional properties; NativeObject and ContainingOccurrence. NativeObject returns the definition of the object - the object without its containing occurrence context. So for a FaceProxy object, NativeObject returns the corresponding face object within the part definition. The ContainingOccurrence property returns the containing object - in this case, the occurrence that contains the face.


Note: When working with an object or its proxy, be aware that calls to their respective Parent properties return different objects. The parent of a proxy object will also be a proxy object. For example, the parent of an EdgeProxy object may be a SurfaceBodyProxy.

The starting point at the top of the path is the ComponentOccurrence. The CreateGeometryProxy method of the ComponentOccurrence object creates the required proxy information for a given face, feature, constraint, and so on.

Sample demonstrating the difference between a proxy and its native object

The following code omits error checking for the sake of clarity and brevity. Always check that return values are of the expected type.

Through the Autodesk Inventor user interface, create a simple part (for example, extrude a circle). Save the part, and then start a new assembly. Place your saved part in the assembly, unground the assembly, move it a little, then save the assembly.

The following code prints the X and Y coordinates of one corner of the range box that encompasses the extrude feature of the part. It demonstrates that different coordinates are returned for the proxy when compared to the native occurrence.

First, obtain the component occurrence from the assembly document. In this case it's simplified as we know the document contains only one.

Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oCompOcc As ComponentOccurrence
Set oCompOcc = oDoc.ComponentDefinition.Occurrences.Item(1)

Then obtain the part component definition to gain access to the part features.

Dim oPartCompDef As PartComponentDefinition
Set oPartCompDef = oCompOcc.Definition

Dim oExtrudeFeature As ExtrudeFeature
Set oExtrudeFeature = oPartCompDef.Features.ExtrudeFeatures.Item(1)

To get the proxy for the feature, use the CreateGeometryProxy method of the component occurrence, with the required feature as an argument.

Dim oExtrudeFeatureProxy As ExtrudeFeatureProxy
oCompOcc.CreateGeometryProxy oExtrudeFeature, oExtrudeFeatureProxy

Print some coordinate data, in this case the X Y values of one corner of the feature rangebox. These figures will differ, indicating that the first set come from the native object, while the second set come from the proxy object - in other words, the second set of values are in the assembly context.

Debug.Print oExtrudeFeature.RangeBox.MaxPoint.X
Debug.Print oExtrudeFeature.RangeBox.MaxPoint.Y

Debug.Print oExtrudeFeatureProxy.RangeBox.MaxPoint.X
Debug.Print oExtrudeFeatureProxy.RangeBox.MaxPoint.Y

The preceding code demonstrated that coordinates for a known point differed according to the context of the feature. Example output might look as follows.

 0.232857970569028 
 0.96726442148297 
 0.177086160521056 
 0.988809173640979

In the assembly context, the part was moved; therefore the coordinates returned by the proxy reflect this move (the first and second lines in the output). These coordinates are different from those returned by the native object, the object definition, with no containing context (the third and fourth lines in the output).

Summary

An object proxy is a reference to an object through a particular occurrence. When the user picks an object (edge, face, loop and so on) in an assembly, they are really picking an object proxy. The various proxies available through the API are derived from their real counterparts and contain the same methods and properties, as well as others specific to proxies (such as NativeObject, which returns the object definition the proxy is paired with). The purpose of object proxies is to provide transformation and assembly context information for occurrences, features, constraints and so on. Object proxies are transparent to the Autodesk Inventor user.

Also consider

To fully understand object proxies, it is important to understand component occurrences and component definitions.



Was this information helpful?