Hi all, I need some help with this function of mine.
Suppose I have the following hierarchy as seen in the attachment.
Assuming that everything in that attachment is of custom nodes (I used 
locators, groups etc. for easy visual, i hope)
and I am trying to grab the Root Node in which its type is 'stkLevel'.

I am trying to fulfill a few conditions:

   1. User can select either the Root Node or the pCube#
   2. If User selects nothing in the scene, it will prompts a warning
   3. If User selects more than 2 Root Node, it will prompts a warning
   4. If User selects 1 or more 'pCube#', it will return the Root Node 
   within the hierarchy
   5. Ultimately, this function must return the full path of the Root Node

def get_stkLevel():
    sel = cmds.ls(selection=True, l=True)
    if len(sel) == 0:
        cmds.warning("Please select something")


    stkLevel_node = cmds.ls(sel, type = "stkLevel")
    if len(sel) > 1:
        if stkLevel_node:
            cmds.warning("Please select a valid stkLevel node")
        else:
            root_list = []
            for item in sel:
                root_node = item.split('|')[1]
                if root_node not in root_list:
                    root_list.append(root_node)
            return cmds.ls(root_list, l=True)[0]
    else:
        return stkLevel_node[0]


I got the issue, where if I select only 1 pCube#, and it returns nothing, 
though it seems to be working if I only select 1 Root Node
While that is one of the issue, can someone kindly guide me if I am writing 
my code correctly?
I asked this because first I am still not that great of a scripter and I 
feel that I am forcing my way through while following those conditions

<https://lh3.googleusercontent.com/-eMvBsvof9FY/V-HgP4mkfQI/AAAAAAAAB24/_8adbg5QUAEvaklzjL00Z8kPPZ0kim0FgCLcB/s1600/hierarchy.jpg>

-- 
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/ecb59d2c-9ab4-4141-99c0-41482ae77027%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to