-
Notifications
You must be signed in to change notification settings - Fork 0
/
hierarchy_helpers.py
43 lines (36 loc) · 947 Bytes
/
hierarchy_helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import maya.cmds as cmds
def get_parent(node):
"""Gets the parent node
Parameters
----------
node : str
Target node
Returns
-------
str
Parent name.
"""
return cmds.listRelatives(node, parent=True)[0]
def get_top_parent(node, max_level = 99):
"""Gets the top parent. If no max level is informed it will get the most (most external) parent node.
Parameters
----------
node : str
Target node
Returns
-------
str
Top most parent name.
"""
current_parent = node
parent = node
level = 1
while current_parent != None:
if level > max_level:
break
current_parent = cmds.listRelatives(current_parent, fullPath=True, parent=True)
if current_parent is not None:
current_parent = current_parent[0]
parent = current_parent
level += 1
return parent