From 4e1afb2b97e04f9c387cca8cca60cf28eeaaf7fd Mon Sep 17 00:00:00 2001 From: miquelcampos Date: Tue, 15 Oct 2024 12:00:28 +0900 Subject: [PATCH] dagmenu.py add support to different naming in space/parent (ikRef) attr. Before only "*ref" suffix was supported #224 --- release/scripts/mgear/core/anim_utils.py | 4 ++- release/scripts/mgear/core/dagmenu.py | 42 +++++++++++++++++------- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/release/scripts/mgear/core/anim_utils.py b/release/scripts/mgear/core/anim_utils.py index 71c5fdf4..4eeae3ec 100644 --- a/release/scripts/mgear/core/anim_utils.py +++ b/release/scripts/mgear/core/anim_utils.py @@ -941,7 +941,9 @@ def ikFkMatch_with_namespace( # keyframes if key: for x in fks_gimbal + [ik_gimbal]: - pm.setKeyframe(x, time=(cmds.currentTime(query=True) - 1.0)) + pm.setKeyframe( + x, time=(cmds.currentTime(query=True) - 1.0) + ) gimbal_exist = True except: pass diff --git a/release/scripts/mgear/core/dagmenu.py b/release/scripts/mgear/core/dagmenu.py index efb0a69e..70b864c0 100644 --- a/release/scripts/mgear/core/dagmenu.py +++ b/release/scripts/mgear/core/dagmenu.py @@ -163,17 +163,25 @@ def _find_rig_root(node): def _get_switch_node_attrs(node, end_string): """ returns list of attr names for given node that match the end_string arg and are not proxy attrs + Args: - node: str - Returns: list of strings + node (TYPE): Description + end_string (str or list): list of string suffix to search in the attr + + Returns: + Returns: list of strings + """ attrs = [] - for attr in cmds.listAttr(node, userDefined=True, keyable=True) or []: - if not attr.lower().endswith(end_string) or cmds.addAttr( - "{}.{}".format(node, attr), query=True, usedAsProxy=True - ): - continue - attrs.append(attr) + if not isinstance(end_string, list): + end_string = [end_string] + for end_str in end_string: + for attr in cmds.listAttr(node, userDefined=True, keyable=True) or []: + if not attr.lower().endswith(end_str) or cmds.addAttr( + "{}.{}".format(node, attr), query=True, usedAsProxy=True + ): + continue + attrs.append(attr) return attrs @@ -357,7 +365,6 @@ def __switch_parent_callback(*args): switch_attr = args[1] switch_idx = args[2] search_token = switch_attr.split("_")[-1].split("ref")[0].split("Ref")[0] - print(search_token) target_control = None # control_01 attr don't standard name ane need to be check @@ -399,6 +406,15 @@ def __switch_parent_callback(*args): target_control_list.append(ctl.stripNamespace()) + if search_token in ["follow"] and not target_control_list: + # in this case we asume that the control holds is own space + # switch attr. This attr is also expected to have simple name + # witout description to witch component belongs. This works only + # if the attr is on a control of the same component that is not a + # genearal uiHost for other components + target_control = uiHost.stripNamespace() + target_control_list.append(target_control) + # gets root node for the given control namespace_value = args[0].split("|")[-1].split(":") if len(namespace_value) > 1: @@ -785,7 +801,8 @@ def mgear_dagmenu_fill(parent_menu, current_control): attrs = _get_switch_node_attrs(current_control, "_blend") attrs2 = _get_switch_node_attrs(current_control, "ref") attrs3 = _get_switch_node_attrs(current_control, "_switch") - if attrs or attrs2 or attrs3: + attrs4 = _get_switch_node_attrs(current_control, "follow") + if attrs or attrs2 or attrs3 or attrs4: ui_host = current_control else: @@ -796,7 +813,8 @@ def mgear_dagmenu_fill(parent_menu, current_control): attrs = _get_switch_node_attrs(ui_host, "_blend") attrs2 = _get_switch_node_attrs(ui_host, "ref") attrs3 = _get_switch_node_attrs(ui_host, "_switch") - if not attrs and not attrs2 and not attrs3: + attrs4 = _get_switch_node_attrs(ui_host, "follow") + if not attrs and not attrs2 and not attrs3 and not attrs4: ui_host = None except ValueError: ui_host = None @@ -1019,7 +1037,7 @@ def add_menu_items(attrs, attr_extension="_blend"): # handles constrains attributes (constrain switches) if ui_host: - for attr in _get_switch_node_attrs(ui_host, "ref"): + for attr in _get_switch_node_attrs(ui_host, ["ref", "follow"]): part, ctl = ( attr.split("_")[0],