it's possible to use pymel for get root.
pm.selected()[0].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 = s_node.name()
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,
fullPath=True)[0]
l_s_parent_nodes.append(parent_node)
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 = s_node.name()
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 !=
"transform":
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
else:
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 python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/43931cdf-c183-47a5-910b-23126d536897%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.