I’ve pushed what is from my perspective an ideal method of collecting an asset from a Maya scene here.
It boils down to this.
# Capture nodes relevant to the model
with pyblish_maya.maintained_selection():
cmds.select(assembly)
nodes = cmds.file(exportSelected=True,
preview=True,
constructionHistory=True,
force=True)
# Reduce to relevant nodes
shapes = cmds.ls(nodes,
noIntermediate=True,
shapes=True,
long=True,
dag=True)
Which does a few important things.
- It gathers all connected nodes, by relying on Maya’s export mechanism
- It then filters it down to data only relevant to validation and export.
From here, data is solely filtered downwards and no new data is added related to this instance.
The benefit is that (1) validation only ever touches data that is actually relevant and (2) a scene can be infinitely messy, but still come out ok. No validation happens on data that isn’t collected, and only relevant data is guaranteed to be collected.
This is in contrast to collecting via cmds.ls(type="mesh")
or similar, which assumes an entire scene is of interest, even though only part of it is ever exported, in this case an assembly by the name of {asset}_GRP
, e.g. ben_GRP
.
Extraction at this point may look like this.
with pyblish_maya.maintained_selection():
cmds.select(instance, noExpand=True)
cmds.file(path,
force=True,
typ="mayaAscii",
exportSelected=True,
constructionHistory=False)
The constructionHistory=False
is the key here. It will extract only what has been collected during collection, which is exactly what we are guaranteed to have validated.