Hi all,
When running “Export Selected..”, the currently selected nodes isn’t the only thing being exported, but also anything leading up to that node; i.e. it’s history.
I’m looking for the most reliable, and efficient way of determining which nodes are being included.
Here’s what I’ve got running currently:
def list_all_history(node):
nodes = list()
nodes.append(node)
nodes.extend(cmds.listRelatives(node,
allDescendents=True,
fullPath=True) or list())
def _list_history(nodes):
history = list()
history.extend(cmds.listHistory(nodes,
allGraphs=True,
allConnections=True))
history.extend(cmds.listConnections(history))
# Expand node paths
history_fullpaths = list()
for node in history:
long_path = cmds.ls(node, long=True)
history_fullpaths.extend(long_path)
return history_fullpaths
# Continue traversing history until all
# relevant nodes are found.
nodes.extend(_list_history(nodes))
# Running once doesn't include some nodes, like file-nodes
# connected to an assigned shader.
nodes.extend(_list_history(nodes))
# De-duplicate
nodes = list(set(nodes))
return nodes
for node in list_all_history(cmds.ls(sl=1)[0]):
print node
Ideally, I’m hoping for an argument on the cmds.file command that returns all expected output, but if nothing like that exists then there’s some work to be done on this function.
For starters, I’m having to _list_history() twice because a shader may be returned the first time around, but it’s connections are not.
The key thing here is to get an accurate representation of what is going to be exported along with the designated nodes.
Any ideas?
Best,
Marcus
Like receiving a reply from heaven.
cmds.file(preview=True, exportSelected=True, force=True)
Solved!