-
Notifications
You must be signed in to change notification settings - Fork 0
/
selection_helpers.py
122 lines (97 loc) · 3.27 KB
/
selection_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import maya.cmds as cmds
import maya.api.OpenMaya as om
def select_joints_on_hierarchy(full_name = False):
"""Select and gets all the joints in a hierarchy.
Parameters
----------
source_node: selection
A node in the hierarchy.
full_name: selection
If set to True it will return the nodes with their full name.
Returns
-------
list:
List of the matching nodes.
"""
return select_type_on_hierarchy("joint", full_name)
def select_constraints_on_hierarchy(full_name = False):
"""Select and gets all the constraints in a hierarchy.
Parameters
----------
source_node: selection
A node in the hierarchy.
full_name: selection
If set to True it will return the nodes with their full name.
Returns
-------
list:
List of the matching nodes.
"""
return select_type_on_hierarchy("constraint", full_name)
def select_locators_on_hierarchy(full_name = False):
"""Select and gets all the locators in a hierarchy.
Parameters
----------
source_node: selection
A node in the hierarchy.
full_name: selection
If set to True it will return the nodes with their full name.
Returns
-------
list:
List of the matching nodes.
"""
return select_transform_based_on_shape_on_hierarchy("locator", full_name)
def select_type_on_hierarchy(node_type, full_name = False):
"""Select and gets all the nodes of the input type in a hierarchy.
Parameters
----------
source_node: selection
A node in the hierarchy.
node_type: str
Node type description.
full_name: selection
If set to True it will return the nodes with their full name.
Returns
-------
list:
List of the matching nodes.
"""
selection = cmds.ls(selection=True)
if not selection:
om.MGlobal.displayError("Please select one object.")
return
all_nodes = cmds.listRelatives(selection, allDescendents=True, shapes=False, type=node_type, fullPath=full_name)
if all_nodes:
cmds.select(all_nodes)
return all_nodes
def select_transform_based_on_shape_on_hierarchy(node_type, full_name = False):
"""Select and gets all the nodes with sahpes of the input type in a hierarchy.
Parameters
----------
source_node: selection
A node in the hierarchy.
node_type: str
Node type (of the sahpe) description.
full_name: selection
If set to True it will return the nodes with their full name.
Returns
-------
list:
List of the matching nodes.
"""
selection = cmds.ls(selection=True)
if not selection:
om.MGlobal.displayError("Please select one object.")
return
all_shapes = []
all_nodes = cmds.listRelatives(selection, allDescendents=True, shapes=False, fullPath=full_name)
for node in all_nodes:
shape = cmds.listRelatives(node, children=True, shapes=True, fullPath=full_name)
if shape and cmds.nodeType(shape) == node_type:
all_shapes.append(node)
if all_shapes:
cmds.select(all_shapes)
return all_shapes
if __name__ == "__main__":
pass