Skip to content

Commit fcd1487

Browse files
authored
Merge pull request #584 from mgear-dev/feature/guide_traversal
Guide traversal support in core dag and component guide using the new…
2 parents 2e97ed3 + 894dd16 commit fcd1487

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

‎release/scripts/mgear/core/dag.py‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,39 @@ def findComponentChildren3(node, name, sideIndex):
255255
children.append(item)
256256

257257
return [pm.PyNode(x) for x in children]
258+
259+
260+
def findComponentChildren4(node: pm.PyNode, name: str, sideIndex: str) -> list[pm.PyNode]:
261+
"""
262+
Return all transform DAG nodes that belong to a given component.
263+
264+
:param pm.PyNode node: The root node whose hierarchy to search.
265+
:param str name: Component name, for example "root" or "ik_hand_root".
266+
:param str sideIndex: Side or index string, for example "C0".
267+
:return: Matching transform nodes belonging to the component.
268+
:rtype: list[pm.PyNode]
269+
"""
270+
name_tokens = name.split("_")
271+
prefix_len = len(name_tokens) + 1
272+
children = set()
273+
274+
# -- All descendant transforms plus the node itself
275+
paths = pm.listRelatives(node.name(),
276+
allDescendents=True,
277+
fullPath=True,
278+
type="transform") or []
279+
280+
for path in paths:
281+
check_name = path.split("|")[-1]
282+
parts = check_name.split("_")
283+
284+
# -- Check if transform belongs to the component
285+
is_component = (len(parts) >= prefix_len
286+
and parts[:prefix_len - 1] == name_tokens
287+
and parts[prefix_len - 1] == sideIndex)
288+
289+
if is_component:
290+
children.add(path)
291+
292+
return [pm.PyNode(x) for x in children]
293+

‎release/scripts/mgear/shifter/component/guide.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ def rename(self, root, newName, newSide, newIndex):
598598
# objList = dag.findComponentChildren(self.parent,
599599
# oldName, oldSideIndex)
600600
# NOTE: Experimenta using findComponentChildren3
601-
objList = dag.findComponentChildren3(self.parent, oldName, oldSideIndex)
601+
objList = dag.findComponentChildren4(self.parent, oldName, oldSideIndex)
602602
newSideIndex = newSide + str(self.values["comp_index"])
603603
objList.append(self.parent)
604604
for obj in objList:

0 commit comments

Comments
 (0)