From 9791dfef7f73f20a1b8d4bbeac638accc71ce8e1 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Fri, 16 Jul 2021 19:27:12 +0300 Subject: Rigify: add utilities for working with rig instance parent chains. --- rigify/utils/rig.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'rigify/utils/rig.py') diff --git a/rigify/utils/rig.py b/rigify/utils/rig.py index fa55c1aa..7969a34f 100644 --- a/rigify/utils/rig.py +++ b/rigify/utils/rig.py @@ -91,6 +91,36 @@ def upgradeMetarigTypes(metarig, revert=False): # Misc #============================================= + +def rig_is_child(rig, parent, *, strict=False): + """ + Checks if the rig is a child of the parent. + Unless strict is True, returns true if the rig and parent are the same. + """ + if parent is None: + return True + + if rig and strict: + rig = rig.rigify_parent + + while rig: + if rig is parent: + return True + + rig = rig.rigify_parent + + return False + + +def get_parent_rigs(rig): + """Returns a list containing the rig and all of its parents.""" + result = [] + while rig: + result.append(rig) + rig = rig.rigify_parent + return result + + def get_resource(resource_name): """ Fetches a rig module by name, and returns it. """ -- cgit v1.2.3