xchangebta.blogg.se

Maya python ls command dont list all duplicates
Maya python ls command dont list all duplicates




So I use the sorted() function on eritems(), and add the flag reverse=True to sort descending. You can get all the keys and values of a dictionary by saying this: for key,value in eritems():īut I need this dictionary sorted by value, not by key, and I need it sorted backwards (in descending order). Then in the next few lines I build the dictionary so that when I sort the names by the ‘|’ count I know I’ll have all the original names in the right order.

maya python ls command dont list all duplicates

The first line makes the list of all transforms that have ‘|’ in them. # now sort the dictionary by value, in reverse, and start renaming.įor key,value in sorted(eritems(),reverse=True, key=lambda (key,value): (value,key)):

maya python ls command dont list all duplicates

# and not worry about losing child objects from the list. this way we can edit names from the bottom of the hierarchy up, # we need to somehow sort this list by the number of '|' appearing in each name. The Python for that sorting looks like this:īadXforms = Then I sorted the dictionary by value (not by key) in reverse order, so that objects lowest in the hierarchy (the ones with the most ‘|’ characters) are renamed first. To prevent this from happening, I built a dictionary where the key is the object’s full name, and the value is the number of times ‘|’ appears in the name. If I renamed ‘group1’ before I renamed ‘group1|pCube1’ then the latter object wouldn’t exist anymore by the time I got to it. The biggest trick here was to make sure that I didn’t rename parent objects before I renamed their children. After that, it renames any object it finds by tacking on a ‘_#’ string to the end, looking for the lowest possible number to use for # in a while loop. It works by analyzing all the transform nodes in your scene and looking for any names that contain ‘|’ which signifies that Maya found another object with the same name and is trying to differentiate them. I wrote a quick script to address this so that objects are always uniquely named. This is especially apparent if you use a lot of custom scripts, which I do all the time. For typical use, this isn’t a huge problem, but seeing as hardly any project I’ve worked on has been “typical” Maya use, duplicate object names end up breaking things more often than they don’t.

maya python ls command dont list all duplicates

When this happens, you have lots of nodes that will have the same name, and Maya will differentiate between them by tacking the name of the parent onto the object using “|” as a separator (pCube1 becomes group1|pCube1, etc). I’ve been working on a project that incorporates a lot of models that were made by duplicating or importing things into a scene over and over again.






Maya python ls command dont list all duplicates