python: create custom property with a simpler add()/new() method
There seem to be many ways (contortions IMHO) to define all parameters of a custom property ranging from
bpy.ops.wm.properties_edit( a='b',... (as reported in console view, although I dought data_path='object' as reported is complete)
o.id_properties_ui( name2 ).update( is_overridable_library=True
ob["_RNA_UI"][ myPropName ]
with pre-3.x and post-3.x answers. Some of these get me part-way but require some knowledge of internal attribute and att/val names that are not obvious. How could I define a LINEAR COLOR to an object 'MyObject' as reported in the console here, with all of these params defined.
data path (if necessary)
FLOAT_ARRAY
property name
is_overridable
description
LINEAR_COLOR
min
max
default values (white color)
bpy.ops.wm.properties_edit(data_path="object", property_name="hair color", property_type='FLOAT_ARRAY', is_overridable_library=True, description="the hair color", use_soft_limits=False, array_length=3, default_float=(1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), min_float=0, max_float=1, soft_min_float=0, soft_max_float=1, precision=3, step_float=1, subtype='COLOR', eval_string="[0.6323933601379395, 0.5497551560401917, 0.21561121940612793]")
What I've come up with seems rediculous, using too many interfaces and a heavy dose of salt:
o = bpy.context.object
obj=o
o[name2] = [1.0, 1.0, 1.0 ] # FLOAT_ARRAY by implication
rna_ui = obj.get('_RNA_UI')
if rna_ui is None:
rna_ui = obj['_RNA_UI'] =
rna_ui = obj.get('_RNA_UI')
rna_ui[name2] = {"description":"color property", # doesn't work!
'type' : 'FLOAT_ARRAY', # probably redundant to array used in initial assignment?
'subtype': 'COLOR', # doesn't work!
"min":0.0,
"max":1.0,
"soft_min":0.0,
"soft_max":1.0,
"is_overridable_library":True, # NOT WORKING!
}
o.id_properties_ui( name2 ).update( description = 'color property')
o.id_properties_ui( name2 ).update( subtype = 'COLOR', min=0, max=1 )
Why is there no object.add_property with similar parameters as the properties_edit method?
0 Comments