Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions release/scripts/mgear/core/dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,39 @@ def findComponentChildren3(node, name, sideIndex):
children.append(item)

return [pm.PyNode(x) for x in children]


def findComponentChildren4(node: pm.PyNode, name: str, sideIndex: str) -> list[pm.PyNode]:
"""
Return all transform DAG nodes that belong to a given component.

:param pm.PyNode node: The root node whose hierarchy to search.
:param str name: Component name, for example "root" or "ik_hand_root".
:param str sideIndex: Side or index string, for example "C0".
:return: Matching transform nodes belonging to the component.
:rtype: list[pm.PyNode]
"""
name_tokens = name.split("_")
prefix_len = len(name_tokens) + 1
children = set()

# -- All descendant transforms plus the node itself
paths = pm.listRelatives(node.name(),
allDescendents=True,
fullPath=True,
type="transform") or []

for path in paths:
check_name = path.split("|")[-1]
parts = check_name.split("_")

# -- Check if transform belongs to the component
is_component = (len(parts) >= prefix_len
and parts[:prefix_len - 1] == name_tokens
and parts[prefix_len - 1] == sideIndex)

if is_component:
children.add(path)

return [pm.PyNode(x) for x in children]

2 changes: 1 addition & 1 deletion release/scripts/mgear/shifter/component/guide.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ def rename(self, root, newName, newSide, newIndex):
# objList = dag.findComponentChildren(self.parent,
# oldName, oldSideIndex)
# NOTE: Experimenta using findComponentChildren3
objList = dag.findComponentChildren3(self.parent, oldName, oldSideIndex)
objList = dag.findComponentChildren4(self.parent, oldName, oldSideIndex)
newSideIndex = newSide + str(self.values["comp_index"])
objList.append(self.parent)
for obj in objList:
Expand Down
Loading