So I did a new code (after some more thinking...) Do feel free to criticize 
and give pointers..
I tested a few scenarios and it seems to work, at least I think it did..

However now I am bumping into another problem.
Say, I have 2 same hierarchy of Root as seen in the attachment but the root 
nodes of these 2 are called 'Root1' and 'Root2' respectively.

If I select |Root1|locator1|pCube1 and |Root2|locator2|pCube2, it will 
returns me "|Root1" as the result. But if I inverse my selection, "|Root2" 
will be my output result.
What is the best way to get around it? Is putting in more checking or 
if-else statements a viable solution?

Sorry for the spam of questions and codes..

def get_selection():
   sel =, long=True)
   stkLevel_node =, type="stkLevel")
   if stkLevel_node:
       if len(stkLevel_node) > 1:
           cmds.warning("Please select 1 stkLevel node only")
           return stkLevel_node
        root_node = []
        for sel_path in sel:
            split_sel_path = sel_path.split('|')[1]
            if split_sel_path not in root_node:
        return, long=True)[0]

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 view this discussion on the web visit
For more options, visit

Reply via email to