Rigify - saving pbone custom properties to metarig #104695
@ -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,42 @@ def write_metarig(obj: ArmatureObject, layers=False, func_name="create",
|
||||
code.append(" except AttributeError:")
|
||||
code.append(" pass")
|
||||
|
||||
# Custom properties
|
||||
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, 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']!r},")
|
||||
Alexander Gavrilov
commented
What if the default isn't equal to the current value? This code doesn't preserve the value anywhere. What if the default isn't equal to the current value? This code doesn't preserve the value anywhere.
Andrej
commented
resolved in resolved in 3677cc454907e82731ac2360be5846d988e48e8c
Alexander Gavrilov
commented
I'd quote default with repr too. Also, get rid of trailing spaces. I'd quote default with repr too. Also, get rid of trailing spaces.
Andrej
commented
resolved in resolved in 076763507e82ff209f546aba4b2ab03061254d9d
|
||||
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 'subtype' in props_data:
|
||||
code.append(f" subtype={props_data['subtype']!r},")
|
||||
Alexander Gavrilov
commented
Rather than doing Rather than doing `'{foo}'`, use `{repr(foo)}`. Manual quoting could be barely tolerated for property names, but for the description it is simply unacceptable.
Andrej
commented
that's really neat thing about that's really neat thing about `repr`, didn't know it can be used that way!
resolved in e2b63e1a4b07ffa8ca59eef5b4b2be17189f49ff
|
||||
if 'description' in props_data:
|
||||
code.append(f" description={props_data['description']!r},")
|
||||
if 'precision' in props_data:
|
||||
code.append(f" precision={props_data['precision']},")
|
||||
if 'step' in props_data:
|
||||
Alexander Gavrilov
commented
This is still not using repr. Also, step and precision should now be supported directly by This is still not using repr. Also, step and precision should now be supported directly by `rna_idprop_ui_create`, I fixed that recently.
Andrej
commented
Resolved in Resolved in ca78100418069ed45b340504ffcb55a03327627e
|
||||
code.append(f" step={props_data['step']},")
|
||||
Alexander Gavrilov
commented
If current_value is actually equal to default, this would be redundant. If current_value is actually equal to default, this would be redundant.
Andrej
commented
resolved in resolved in 076763507e82ff209f546aba4b2ab03061254d9d
|
||||
code.append(f" )")
|
||||
if props_data['default'] != current_value:
|
||||
code.append(f" pbone[{custom_property!r}] = {current_value}")
|
||||
|
||||
# Constraints
|
||||
for con in pbone.constraints:
|
||||
code.append(" con = pbone.constraints.new(%r)" % con.type)
|
||||
|
Loading…
Reference in New Issue
Block a user
Iterate over
items()
to get both key and value.resolved in
3677cc4549