Developer Desktop - Importing Assemblies with CGM InterOP
By: Stacey Hunvald, InterOp Engineer
Have you had a chance to look at our new interface for assembly management with CGM InterOp?
The new interface has been designed to allow users easy access to assembly data before importing an assembly’s b-reps. Assembly tree data is imported into a product structure which provides fine grained control for how the remaining data is imported.
The imported assembly tree data is called a Product Structure and is managed through the CGMInputProductStructure class. The Product Structure is a tree whose nodes contain reference and instance data for each part and sub-assembly of the model. Reference data states which part or subassembly model information is specified by each node in the Product Structure and provides access to the name of the document that specifies that portion of the model. (In the case of monolithic assemblies in which all parts and subassemblies are contained in the same larger model, reference data provides access to the area within the document that specifies that portion of the model.) Because a part or sub-assembly is often used repeatedly in the same assembly, reference data is often not unique to a particular node. Instance data is associated with the specific usage of a part or sub-assembly within the assembly tree, and contains data specific to each use within the assembly tree, including the instance's name and its transform for physically locating it within the assembly. Reference and instance data objects for each node can be used to query information about the model and traverse the Product Structure tree.
To read a file (part or assembly) with CGM InterOp, one must first import the CGMInputProductStructure. This is done via the CGMProductStructureImporter class’s Import() method, which creates the CGMInputProductStructure from the input document.
Once the CGMInputProductStructure has been obtained, its methods can be used to access details about the parts and subassemblies that make up the model, including part names, instance transforms, and the files (or area within a monolithic file) in which the b-rep data for that node can be found. This information is available before any actual b-rep data for the model has been imported, and therefore can be used to control the import of the data.
To access the references from the product structure, start with the root node or nodes. Root nodes are the highest-level subassemblies and parts in the model, just one level below the Product Structure itself, which occupies the base node of the tree. Using the method GetRootInstancesCount(), determine the number of root nodes present and use this information to loop through the root nodes. Get the data associated with each root node by using the GetRootInstance(). The reference info can then be accessed from the instances as follows:
After obtaining each of the roots, the tree can be traversed by recursively navigating the nodes and utilizing the reference and instance data on each as desired. A branch of the Product Structure tree always terminates with a part reference (as opposed to a sub-assembly), so the recursion can be controlled by looking for nodes associated with parts using the IsPart() method of the CGMInputPSReference class as shown:
All this adds up to efficient and fine control over assembly translation and allows users to optimize their workflows as they desire. For instance, an importer may display the assembly tree and allow the end user to selectively import portions of the assembly, to avoid translating data that is not immediately needed. Alternatively, one might opt to display each part as the model is translated so that users do not have to wait until the entire assembly is translated to see some of the model. Additionally, users can efficiently map the model into their own proprietary assembly and feature tree structures by directly reading and mapping each part to their desired structure rather than having to parse an entire assembly translation after a full import . The interface of CGM InterOp is designed to make all these workflows and more as easy and efficient as possible.
Return to Fall 2011 Articles