it's possible to use pymel for get root.

I use to function for get parent by type.

The first it's for get all parent of my node.
The second it's for check type of parent and break when i found my type. 
It's possible to transform this function for works with particular 
attribute or other system.
It's easy to add check selection (if is root, selection number, etc, etc).

def get_all_parents(s_node):

    !@Brief Get all parents of given node.

    @type s_node: string
    @param s_node: Node name for start surch.

    @rtype: list(string)
    @return: List of all parents

    if not isinstance(s_node, basestring):
        s_node =

    l_s_parent_nodes = list()
    current_node = s_node
    while cmds.listRelatives(current_node, parent=True, fullPath=True):
        parent_node = cmds.listRelatives(current_node, parent=True, 
        current_node = parent_node

    return l_s_parent_nodes

def get_parent_by_type(s_node, node_type=None):

    !@brief Find first parent from given node type

    @type s_node: string
    @param s_node: Node name for start surch.
    @type node_type: string
    @param node_type: Type you want to surch

    @rtype: string
    @return: Parent node found. None if don't found node.

    if not isinstance(s_node, basestring):
        s_node =

    l_s_parent_nodes = get_all_parents(s_node)
    for s_parent_node in l_s_parent_nodes:

        if cmds.nodeType(s_parent_node) == "transform" and node_type != 
            l_s_shape_nodes = cmds.listRelatives(s_parent_node, shapes=True, 
fullPath=True, type=node_type)
            if l_s_shape_nodes:
                return s_parent_node
            return s_parent_node

    return None

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