Assembly Tree Node IDs
When authoring the assembly structure using the AssemblyTree API of libsc, each creation function returns an ID to identify the newly created object.
As an example:
The parameter of CreateAssemblyTreeRoot (in this case, "root_node_id") is an out parameter. The id returned in "root_node_id" is needed as input for other functions:
Every node (assembly, part, body instance, PMI, view, etc.) in the assembly tree will have an associated ID that is determined during authoring and will not change.
The IDs start at zero (which will usually be the assembly), and the IDs generated will increment by 1 meaning that the whole ID set will go from 0 to n.
When exporting to an XML file, the IDs will be the same in the XML as the ones you got when authoring.
This is the same scenario when you use Converter with the command line option --output_xml_assemblytree.
Also it's important to note that when the data is stored in the StreamCache, IDs will still stay the same, which means that the IDs created during authoring, the IDs in the XML, and the IDs returned in the web client will be the same.
Loading Multiple Files Into the Same Viewing Session
Assuming two assemblies: "A" and "B".
We generate a StreamCache file for both:
- For "A" the IDs range from 0 to 399.
- For "B" the IDs range from 0 to 499.
In the web client, we initially load "A" with the WebViewer constructor.
In addition, we load B into our Communicator.WebViewer object ("hwv" in this sample) using the loadSubTreeFromModel() function from the model object:
In this case, it isn't obvious how to reference a node in the "B" tree, since B's range of node IDs overlaps with A's.
To make it possible to uniquely identify nodes, the IDs of B are automatically shifted to the lowest available ID of the existing scene. The function getLowestAvailableNodeId() should be called before loading another model into the scene – in this case, right before loading B. It would return "400" as the lowest available ID. Then you can use that number internally to make your B assembly XML IDs match the IDs on the web client.
Here's a sample function call:
In this scenario, since A has already reserved the IDs from 0 to 399, the range for B will be shifted from 0–499 to 400–899. It's up to the developer to correctly map those shifted IDs back to the original IDs in the XML of the model.