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 = cmds.ls(selection=True, long=True)
   stkLevel_node = cmds.ls(sel, type="stkLevel")
   if stkLevel_node:
       if len(stkLevel_node) > 1:
           cmds.warning("Please select 1 stkLevel node only")
       else:
           return stkLevel_node
   else:
        root_node = []
        for sel_path in sel:
            split_sel_path = sel_path.split('|')[1]
            if split_sel_path not in root_node:
                root_stack.append(split_sel_path)
        return cmds.ls(root_node, 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 python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/15fb02f2-7cbf-4b2c-a3ef-58ccb8ebc86f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to