Skip to content

Commit 7731860

Browse files
Add 'sort_nodes_by_depth' for tools that require a stable hierarchy.
Used by issue #200.
1 parent c224415 commit 7731860

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

python/mmSolver/utils/node.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,25 @@ def get_node_parents(node):
122122
return parent_nodes
123123

124124

125+
def sort_nodes_by_depth(nodes, reverse=False):
126+
"""
127+
Sort nodes by depth, shallow nodes first.
128+
129+
:param nodes: List of Maya DAG node paths.
130+
:type nodes: [str, ..]
131+
132+
:returns: List of sorted nodes.
133+
:rtype: [str, ..]
134+
"""
135+
assert isinstance(nodes, (list, set))
136+
137+
def func(a):
138+
return a.count('|')
139+
140+
nodes = sorted(nodes, key=func, reverse=reverse)
141+
return nodes
142+
143+
125144
def get_as_selection_list_apione(paths):
126145
"""
127146
Get a Maya API selection list with the given valid Maya node paths.

0 commit comments

Comments
 (0)