My goal is to export the root node, all children and everything required to recreate an asset (for example, materials), but not include anything extraneous (for example, a lighting rig used to demo the asset, but that is logically not part of the asset, and is not a child of the asset's root node either).
As a simple example, imagine the scene contains a sphere and a cube. Neither is a child of the other in the DAG. If I pass in the root node of the sphere, only the sphere should appear in the export. If I select the root node of the cube, only the cube should appear.
I thought my selection logic was incorrect, but I can see in the Script Editor that the correct nodes (and no others) are being selected.
But, no matter which root node I pass in, the whole scene (sphere and cube) are exported. Is there a condition I must remove from exportSelected
, or another condition I must add?
import pymel.core as core
core.select(clear=True)
core.select(root, hierarchy=True) # selects node hierarchy as expected
core.select(root, allDependencyNodes=True, add=True) # selects textures
# (although it selects unrelated textures too)
core.system.exportSelected(target_path, shader=True, preserveReferences=True)
# but this exports the whole scene,
# including nodes that were not selected by the lines above