fix [#30905] Operator preset save doesn't serialize PropertyGroups

fix based on patch by Julien Rivaud (frnchfrgg), but re-written a bit differently not to be operator specific.
This commit is contained in:
Campbell Barton 2012-05-11 18:55:14 +00:00
parent a045ad9055
commit 564a6c2353
1 changed files with 26 additions and 7 deletions

View File

@ -93,6 +93,29 @@ class AddPresetBase():
filepath,
preset_menu_class.preset_xml_map)
else:
def rna_recursiev_attr_expand(value, rna_path_step, level):
if isinstance(value, bpy.types.PropertyGroup):
for sub_value_attr in value.bl_rna.properties.keys():
if sub_value_attr == "rna_type":
continue
sub_value = getattr(value, sub_value_attr)
rna_recursiev_attr_expand(sub_value, "%s.%s" % (rna_path_step, sub_value_attr), level)
elif type(value).__name__ == "bpy_prop_collection_idprop": # could use nicer method
file_preset.write("%s.clear()\n" % rna_path_step)
for sub_value in value:
file_preset.write("item_sub_%d = %s.add()\n" % (level, rna_path_step))
rna_recursiev_attr_expand(sub_value, "item_sub_%d" % level, level + 1)
else:
# convert thin wrapped sequences
# to simple lists to repr()
try:
value = value[:]
except:
pass
file_preset.write("%s = %r\n" % (rna_path_step, value))
file_preset = open(filepath, 'w')
file_preset.write("import bpy\n")
@ -104,14 +127,10 @@ class AddPresetBase():
for rna_path in self.preset_values:
value = eval(rna_path)
# convert thin wrapped sequences
# to simple lists to repr()
try:
value = value[:]
except:
pass
rna_recursiev_attr_expand(value, rna_path, 1)
file_preset.write("%s = %r\n" % (rna_path, value))
file_preset.close()