findind all the nested group and objects in the hirerachy and renaming them to a new name.

25 views
Skip to first unread message

Nitin Singh

unread,
Jan 9, 2014, 1:19:28 PM1/9/14
to python_in...@googlegroups.com


hello Guys,

I am having a issue,
I want to rename a scene which has lots of group's and nested objects in them.

i tried every thing i know but couldn't figure it out, any help will be highly appreciated.


i have attached a demo scene to showcase my problem
test scene has only 2 level of groups but in my scene i have more than 20 nested groups and in future i might have less or more so its very important for me to figure out how it is going to count the level of hierarchy and rename every single element in it if i want to.


please help.

thanks a lot in advance.
testScene_Hierarchy.mb

Ævar Guðmundsson

unread,
Jan 9, 2014, 8:46:58 PM1/9/14
to python_in...@googlegroups.com
What you need is a recursive function

http://www.python-course.eu/recursive_functions.php

http://en.m.wikipedia.org/wiki/Graph_traversal
( depth first approach is good for all things Maya related )

Basically it's a function that keeps calling itself until it doesn't find any further branches to climb

Works great in Maya for all things connected to any other thing, similar to how the Houdini tree traversal worked before they botched the core traversal with subnets..

It's quite fun to write, in pseudo-code ( am on a phone, just answering since you haven't gotten one yet, will send you an actual example later ) :

Def crawl:
For thing found:
Tag checked
Call crawl on all results
Return

Eventually it runs out of things to do and returns, kind of like a while loop but instead of a parameter that stops it, it always stops when there is nothing else to do.

Hope this helps, and you have fun reading the links, the wording in there sounds a lot more than the trick is.

Nitin Singh

unread,
Jan 10, 2014, 1:21:33 PM1/10/14
to python_in...@googlegroups.com
thanks a lot for the reply , i will definitely use this now :)
Reply all
Reply to author
Forward
0 new messages