Documentation

Support

Asset Transformer SDK


User Manual

Python API

C# API

Changelog

Discussions

Asset Transformer SDK

Product structure

Use this feature to manage and manipulate the product structure of 3D scenes, including creating hierarchies, sorting occurrences, and optimizing for performance.
Read time 1 minuteLast updated 21 hours ago

API functions: Product structure is the scene hierarchy of occurrences. It can be seen as a tree where we can go down to the leaf using scene.getChildren and go up to the root using scene.getParent. We can manipulate this product structure to change order and parenting relations between occurences.

Code example

Create new occurrences

Let's take an example where we create a new product structure from scratch to match the following tree:
Root|- zz|- |- t|- |- n|- a|- b
def createTestProductStructure():root = scene.getRoot()zz_occurrence = scene.createOccurrence(name="zz", parent=root)t_occurrence = scene.createOccurrence(name="t", parent=zz_occurrence)n_occurrence = scene.createOccurrence(name="n", parent=zz_occurrence)a_occurrence = scene.createOccurrence(name="a", parent=root)b_occurrence = scene.createOccurrence(name="b", parent=root)

Print the hierarchy tree

We want to be able to print the name of each occurrence and have the same representation in the console than the structure described above.
# Go through the product structure using "depth first" recursive methoddef dfPrintOccurrencesName(offset, occurrence): print(offset + scene.getOccurrenceName(occurrence)) offset = offset + " |- " for child in scene.getChildren(occurrence): dfPrintOccurrencesName(offset, child)

Manipulate the product structure

We want to manipulate the created hierarchy to sort the occurrences based on the alphabetical order of their names.
# Sort a product structure based on occurrences name alphabetical orderdef sortOccurrencesRecursively(occurrence): children = scene.getChildren(occurrence) if not children: return names = core.getProperties(children, "Name") # This built-in method retrieve all the names of an occurrence list children_with_names = zip(children, names) sorted_children_with_names = sorted(children_with_names, key=lambda x: x[1]) sorted_children = [child for child, name in sorted_children_with_names] for child in sorted_children: sortRecursively(child) scene.setParent(child, occurrence)

Output

Root|- a|- b|- zz|- |- n|- |- t