Rigify - saving pbone custom properties to metarig #104695
@ -295,6 +295,7 @@ def write_metarig(obj: ArmatureObject, layers=False, func_name="create",
|
|||||||
"""
|
"""
|
||||||
code = [
|
code = [
|
||||||
"import bpy\n",
|
"import bpy\n",
|
||||||
|
"from rna_prop_ui import rna_idprop_ui_create\n",
|
||||||
"from mathutils import Color\n\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(" except AttributeError:")
|
||||||
code.append(" pass")
|
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
|
# Constraints
|
||||||
for con in pbone.constraints:
|
for con in pbone.constraints:
|
||||||
code.append(" con = pbone.constraints.new(%r)" % con.type)
|
code.append(" con = pbone.constraints.new(%r)" % con.type)
|
||||||
|
Loading…
Reference in New Issue
Block a user