Maya python ls command dont list all duplicates
- #Maya python ls command dont list all duplicates full#
- #Maya python ls command dont list all duplicates code#
Anywho, try it out and let me know if it works for you:
#Maya python ls command dont list all duplicates code#
Possible downfalls include the fact that I’ve only tested this on a limited number of scene files, I’m fairly new to Maya so it’s possible I’ve overlooked some test cases, and there may be more cleanup that can be done to this code (working fast on deadline). This processed the complex scene above over 200x as fast: 10 seconds instead of 40 minutes! The benefits I see in this method are a smaller data set to begin with (in my case: 2434 “instance groups” to work with instead of 12260 instances) as well as linear scaling with the size of the data set, O(n) instead of O(n^2). It’s possible that one run through will not find all the instances so I repeat that process as many times as necessary (in the case of the complex scene I mentioned it has to run twice). I generate a list of those nodes (parents to so-called “instance groups”) once then iterate through them duplicating and deleting them.
#Maya python ls command dont list all duplicates full#
For the instanced leaf nodes I get the full path to those nodes and then look for the highest level node (closest to root node) in that path that is also instanced. Instead of getting all the instances in the entire scene I decided to check the DAG leaf nodes. I took the basic idea and have written my own version. With the uninstance() function calling getInstances() for every one of those instances this means waiting for 40 minutes to uninstance the entire scene! For example, one scene file I tested returns 12260 instances through the getInstances() function. However, the method seems to be terribly inefficient with deeply nested instances and a large number of DAG nodes. I was excited to find this post as we have a lot of uninstancing to do here at work. Selection_iter = om.MItSelectionList(selection)ĭagInst = om.MDagPath.isInstanced(dagPath) Om.MGlobal.getActiveSelectionList(selection) This is what I have so far, if you have a second to help it would be very kind, my scene is a nightmare of objects disappearing when I combine : ( In an ideal world, all objects that are instances of the same kind of the selection would be uninstanced, and the rest of the scene would be untouched. I tried to make it work with the “getAllPaths” command of the MDagPath, with no success – I have barely an idea of the api code I am writing. It works to a certain extent, but some objects are not uninstanced – I guess because the level of grouping is deeper than a first “pass”. So I am trying to rewrite your code so it works with only the selection. I am pretty decent in Python Maya though. I am a totally ignorant in Maya API, I just don’t understand why, how, etc. Thank you very much for your script, this thing caused me many problems last week at work. Mc.duplicate(parent, renameChildren=True)
Parent = mc.listRelatives(instances, parent=True, fullPath=True) And since the getInstances() function returns a list parent-first, this works out great: def uninstance(): But when you have the situation I list above, the solution I found is this: You can actually duplicate the instances parent, then delete the original parent, which will (via a loop) cleanly uninstance everything in the scene. Like I just mentioned, most solutions I’ve found explain you can just ‘duplicate the instance’ to solve this problem, and this works on an individual instance that has no parent node that is an instance. But if you have a say ten spheres all instanced, then you make two groups of five, then instance those groups, and parent all the groups, then instance that parent… very quickly things get hairy: You try and uninstance a leaf by duplicating it, and now the duplicate appears in every other parental instance! This function will return a list of all the instances in the scene, nice! I have yet to find any other function that can do this via mel.īut how would you actually uninstance them? I worked on this problem quite a bit: If you simply have a bunch of leaf nodes that are instanced, it’s not hard to do.
Instanced = om.MItDag.isInstanced(iterDag) IterDag = om.MItDag(om.MItDag.kBreadthFirst) Poking around a bit in the API however, it only takes a few lines of code: # Python code Maya makes it easy to create an instance of a node, but I’ve found no built-in way to query what nodes in the scene are instanced.