Like receiving a reply from heaven. cmds.file(preview=True, exportSelected=True, force=True)
Solved! On 11 October 2014 08:59, Marcus Ottosson <[email protected]> wrote: > 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 > > -- > *Marcus Ottosson* > [email protected] > -- *Marcus Ottosson* [email protected] -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBwpxB2UO8hV%3D3UNM6k2NAtTWt1Th-G_PKHEAo3O97J%2Bg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
