Creating object custom property with name like "prop.r", how to not overwrite _RNA_UI

I would like to, via a Python script, add a number of custom properties to an object that already has custom properties - under the Object datablock, it may have dozens of custom properties with their own tooltips already.

How do I add a property with a name like “prop.r” to the object without overwriting all the information I already have about all the other custom properties?

I have this code:

import bpy

ob = bpy.context.active_object

#Part 1
bpy.types.Object.one = bpy.props.FloatProperty(name="does this setting do anything at all?", description="one hundred million", default=1.000, min=0.000, max=1.000)
ob.one = 0.6

#Part 2
ob["one.l"] = 1.000
ob["_RNA_UI"] = {"one.l":{"min":0.0, "max":1.0, "description":"Left One"}}


Part 1 can add a property with a maximum and minimum setting without overwriting any other custom properties’ data, but the property’s name cannot have a period in it, so trying to create one.l in Part 1 won’t work.
Part 2 can add a property with a name like “one.l” but running this script overwrites any tooltips I already have on the custom properties of the selected object.

How can I modify either method to add a custom property with a name like “prop.r” without overwriting the maximum, minimum, and tooltip of every other custom property that already exists?

edit: Like this, apparently:


import bpy

ob = bpy.context.active_object

bpy.types.Object.one = bpy.props.FloatProperty(name="does this setting do anything at all?", description="one hundred million", default=1.000, min=0.000, max=1.000)
ob.one = 0.6

ob["one.l"] = 1.000
ob["_RNA_UI"]['one.l'] = {"min":0.0, "max":1.0, "description":"Left One"}

That works for Part 2, but is there a way to fix part 1 to do the same thing?

Edit again:
This method doesn’t seem to really set the upper and lower bounds where they should be. I am able to toggle the value for “one.l” all the way up to 10000 and down to -10000, only after I release does it get snapped down to 1.0 or up to 0.0. If I access “one.l” from a custom panel in the 3D view, where I have a slider mapped to one.l, that slider will look like it is always halfway between the maximum and minimum. If I have another custom property, say “one.r”, made to look just about exactly like “one.l” except made by clicking through “add custom property”… it will not have this problem. Why might this be?

Hi Solvent,

Have you tried a propertygroup / pointerproperty construct ?
the following example is from http://www.blender.org/documentation/blender_python_api_2_60_1/info_overview.html


<i># Create new property group with a sub property</i>
<i># bpy.data.materials[0].my_custom_props.sub_group.my_float</i>
<b>import</b> <b>bpy</b>

<b>class</b> <b>MyMaterialSubProps</b>(bpy.types.PropertyGroup):
    my_float = bpy.props.FloatProperty()

<b>class</b> <b>MyMaterialGroupProps</b>(bpy.types.PropertyGroup):
    sub_group = bpy.props.PointerProperty(type=MyMaterialSubProps)

<b>def</b> register():
    bpy.utils.register_class(MyMaterialSubProps)
    bpy.utils.register_class(MyMaterialGroupProps)
    bpy.types.Material.my_custom_props = bpy.props.PointerProperty(type=MyMaterialGroupProps)

<b>def</b> unregister():
    <b>del</b> bpy.types.Material.my_custom_props
    bpy.utils.unregister_class(MyMaterialGroupProps)
    bpy.utils.unregister_class(MyMaterialSubProps)

<b>if</b> __name__ == "__main__":
    register()


Hello,

No, I’m afraid I haven’t, because I don’t think that’s what I’m looking for. I’m not trying to add a property “prop” with the subproperty “r” to an object, I’m trying to add a single ID-property named “prop.r”. I can do that by clicking “Add custom property” and entering the name, (even a name with “.” in it, which is not good for non-ID-properties,) value, maximum, minimum, and tooltip for each property individually. That’s what I was trying to automate with this script, but I kept getting results that were not exactly like what I got with the manual method.

I just figured out what the difference was in the updated second method: I need to define “soft_min” and “soft_max” as well as the maximum and minimum for the ID-property, and that will get the behavior of the script-made and button-made properties in line. For example:

import bpy
ob = bpy.context.active_object
ob["Script.Added"] = 0.000
ob["_RNA_UI"]['Script.Added'] = {"min":0.0, "max":1.0, "description":"Try to drag me past my bounds!"}
#Use the following line instead of the previous one and it works!
#ob["_RNA_UI"]['Script.Added'] = {"min":0.0, "max":1.0, "soft_min":0.0, "soft_max":1.0, "description":"Try to drag me past my bounds!"}

Here’s a file to show what doesn’t work and what does:

ScriptAndButtonDifferences.blend (501 KB)

So I think this is solved: I think this is how to add ID-properties via a script and get the same results that using the button does.

Thanks for your help!