From 48c2e622aaa6820682bf9e24bf88e06401693147 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Thu, 15 Jun 2023 13:57:43 +0500 Subject: [PATCH 1/6] Rigify - saving pbone custom properties to metarig --- rigify/utils/rig.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/rigify/utils/rig.py b/rigify/utils/rig.py index 71201eab1..185ed1c8e 100644 --- a/rigify/utils/rig.py +++ b/rigify/utils/rig.py @@ -295,6 +295,7 @@ def write_metarig(obj: ArmatureObject, layers=False, func_name="create", """ code = [ "import bpy\n", + "from rna_prop_ui import rna_idprop_ui_create\n", "from mathutils import Color\n\n", ] @@ -412,6 +413,36 @@ def write_metarig(obj: ArmatureObject, layers=False, func_name="create", code.append(" except AttributeError:") code.append(" pass") + # Custom properties + custom_properties = [ + custom_property for custom_property in pbone.keys() + if custom_property not in pbone.bl_rna.properties.keys() + and type(pbone[custom_property]) in (float, int) + ] + + if custom_properties: + code.append(' # custom properties') + + for custom_property in custom_properties: + props_data = pbone.id_properties_ui(custom_property).as_dict() + code.append(f" rna_idprop_ui_create(") + code.append(f" pbone, ") + code.append(f" '{custom_property}', ") + code.append(f" default={props_data['default']}, ") + if 'min' in props_data: + code.append(f" min={props_data['min']}, ") + if 'max' in props_data: + code.append(f" max={props_data['max']}, ") + if 'soft_min' in props_data: + code.append(f" soft_min={props_data['soft_min']}, ") + if 'soft_max' in props_data: + code.append(f" soft_max={props_data['soft_max']}, ") + if 'description' in props_data: + code.append(f" description='{props_data['description']}'") + code.append(f" )") + if 'precision' in props_data: + code.append(f" pbone.id_properties_ui('{custom_property}').update(precision={props_data['precision']})") + # Constraints for con in pbone.constraints: code.append(" con = pbone.constraints.new(%r)" % con.type) -- 2.30.2 From e2b63e1a4b07ffa8ca59eef5b4b2be17189f49ff Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Sat, 9 Sep 2023 21:29:49 +0500 Subject: [PATCH 2/6] Rigify - quoting data using repr to make it more safe --- rigify/utils/rig.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rigify/utils/rig.py b/rigify/utils/rig.py index 185ed1c8e..53f65e838 100644 --- a/rigify/utils/rig.py +++ b/rigify/utils/rig.py @@ -427,7 +427,7 @@ def write_metarig(obj: ArmatureObject, layers=False, func_name="create", props_data = pbone.id_properties_ui(custom_property).as_dict() code.append(f" rna_idprop_ui_create(") code.append(f" pbone, ") - code.append(f" '{custom_property}', ") + code.append(f" {custom_property!r}, ") code.append(f" default={props_data['default']}, ") if 'min' in props_data: code.append(f" min={props_data['min']}, ") @@ -438,7 +438,7 @@ def write_metarig(obj: ArmatureObject, layers=False, func_name="create", if 'soft_max' in props_data: code.append(f" soft_max={props_data['soft_max']}, ") if 'description' in props_data: - code.append(f" description='{props_data['description']}'") + code.append(f" description={props_data['description']!r}") code.append(f" )") if 'precision' in props_data: code.append(f" pbone.id_properties_ui('{custom_property}').update(precision={props_data['precision']})") -- 2.30.2 From 3677cc454907e82731ac2360be5846d988e48e8c Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Sat, 9 Sep 2023 21:50:21 +0500 Subject: [PATCH 3/6] Rigify - considering current custom property value --- rigify/utils/rig.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/rigify/utils/rig.py b/rigify/utils/rig.py index 53f65e838..fa51cf703 100644 --- a/rigify/utils/rig.py +++ b/rigify/utils/rig.py @@ -414,16 +414,16 @@ def write_metarig(obj: ArmatureObject, layers=False, func_name="create", code.append(" pass") # Custom properties - custom_properties = [ - custom_property for custom_property in pbone.keys() - if custom_property not in pbone.bl_rna.properties.keys() - and type(pbone[custom_property]) in (float, int) - ] + custom_properties = { + property_name: value for property_name, value in pbone.items() + if property_name not in pbone.bl_rna.properties.keys() + and type(pbone[property_name]) in (float, int) + } if custom_properties: code.append(' # custom properties') - for custom_property in custom_properties: + for custom_property, current_value in custom_properties.items(): props_data = pbone.id_properties_ui(custom_property).as_dict() code.append(f" rna_idprop_ui_create(") code.append(f" pbone, ") @@ -442,6 +442,7 @@ def write_metarig(obj: ArmatureObject, layers=False, func_name="create", code.append(f" )") if 'precision' in props_data: code.append(f" pbone.id_properties_ui('{custom_property}').update(precision={props_data['precision']})") + code.append(f" pbone[{custom_property!r}] = {current_value}") # Constraints for con in pbone.constraints: -- 2.30.2 From 497685b06d12e8b8947302c2068e8179ba4cc107 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Sat, 9 Sep 2023 21:50:34 +0500 Subject: [PATCH 4/6] Rigify - also storing custom property subtype --- rigify/utils/rig.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rigify/utils/rig.py b/rigify/utils/rig.py index fa51cf703..5151d3077 100644 --- a/rigify/utils/rig.py +++ b/rigify/utils/rig.py @@ -437,6 +437,8 @@ def write_metarig(obj: ArmatureObject, layers=False, func_name="create", code.append(f" soft_min={props_data['soft_min']}, ") if 'soft_max' in props_data: code.append(f" soft_max={props_data['soft_max']}, ") + if 'subtype' in props_data: + code.append(f" subtype={props_data['subtype']!r}, ") if 'description' in props_data: code.append(f" description={props_data['description']!r}") code.append(f" )") -- 2.30.2 From 076763507e82ff209f546aba4b2ab03061254d9d Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 25 Sep 2023 22:36:21 +0500 Subject: [PATCH 5/6] Rigify - saving pbone custom properties minor changes Fixed: - trailing spaces - repr for default value - don't set current value if it's the same as default --- rigify/utils/rig.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/rigify/utils/rig.py b/rigify/utils/rig.py index 5151d3077..29989ef50 100644 --- a/rigify/utils/rig.py +++ b/rigify/utils/rig.py @@ -426,25 +426,26 @@ def write_metarig(obj: ArmatureObject, layers=False, func_name="create", for custom_property, current_value in custom_properties.items(): props_data = pbone.id_properties_ui(custom_property).as_dict() code.append(f" rna_idprop_ui_create(") - code.append(f" pbone, ") - code.append(f" {custom_property!r}, ") - code.append(f" default={props_data['default']}, ") + code.append(f" pbone,") + code.append(f" {custom_property!r},") + code.append(f" default={props_data['default']!r},") if 'min' in props_data: - code.append(f" min={props_data['min']}, ") + code.append(f" min={props_data['min']},") if 'max' in props_data: - code.append(f" max={props_data['max']}, ") + code.append(f" max={props_data['max']},") if 'soft_min' in props_data: - code.append(f" soft_min={props_data['soft_min']}, ") + code.append(f" soft_min={props_data['soft_min']},") if 'soft_max' in props_data: - code.append(f" soft_max={props_data['soft_max']}, ") + code.append(f" soft_max={props_data['soft_max']},") if 'subtype' in props_data: - code.append(f" subtype={props_data['subtype']!r}, ") + code.append(f" subtype={props_data['subtype']!r},") if 'description' in props_data: code.append(f" description={props_data['description']!r}") code.append(f" )") if 'precision' in props_data: - code.append(f" pbone.id_properties_ui('{custom_property}').update(precision={props_data['precision']})") - code.append(f" pbone[{custom_property!r}] = {current_value}") + code.append(f" pbone.id_properties_ui({custom_property!r}).update(precision={props_data['precision']})") + if props_data['default'] != current_value: + code.append(f" pbone[{custom_property!r}] = {current_value}") # Constraints for con in pbone.constraints: -- 2.30.2 From ca78100418069ed45b340504ffcb55a03327627e Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 25 Sep 2023 22:55:34 +0500 Subject: [PATCH 6/6] Rigify - adapt #112712 --- rigify/utils/rig.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/rigify/utils/rig.py b/rigify/utils/rig.py index 29989ef50..010c88f71 100644 --- a/rigify/utils/rig.py +++ b/rigify/utils/rig.py @@ -440,10 +440,12 @@ def write_metarig(obj: ArmatureObject, layers=False, func_name="create", if 'subtype' in props_data: code.append(f" subtype={props_data['subtype']!r},") if 'description' in props_data: - code.append(f" description={props_data['description']!r}") - code.append(f" )") + code.append(f" description={props_data['description']!r},") if 'precision' in props_data: - code.append(f" pbone.id_properties_ui({custom_property!r}).update(precision={props_data['precision']})") + code.append(f" precision={props_data['precision']},") + if 'step' in props_data: + code.append(f" step={props_data['step']},") + code.append(f" )") if props_data['default'] != current_value: code.append(f" pbone[{custom_property!r}] = {current_value}") -- 2.30.2