I am trying to add some custom ID Properties to an object and have those properties bound by the min/max values.
The _RNA_UI property is supposed to help, but it only seems to work on the last property applied.
If you run this code, an Empty will be created. Select the empty and chose the Object context in the Properties panel. Under Custom Properties there will be new properties. If you scrub the value for “use_caps” you will find that it always snaps into the correct Min/Max range. But the other properties do not.
Can someone explain how to make the Min/Max work for all ID Properties that I add under code?
import bpy
from bpy.props import *
def createEmpty(passedName):
try:
ob = bpy.data.objects.new(passedName, None)
bpy.context.scene.objects.link(ob)
print("createEmpty [" + passedName + "].")
except:
ob = None
print("createEmpty [" + passedName + "] failed!")
return ob
def fetchIfObject (passedName= ""):
try:
result = bpy.data.objects[passedName]
except:
result = None
return result
# Create an Empty and call it mt_BlendText.
obj_BlendText = fetchIfObject("mt_BlendText")
if obj_BlendText == None:
obj_BlendText = createEmpty("mt_BlendText")
else:
print("BlendText already exists and is assumed to be correctly created and populated.")
#http://wiki.blender.org/index.php/Doc:2.5/Manual/Extensions/Python/Properties
# NOTE: ID-Properties only allow Int,Float and Strings.
# Using ID-Properties to hold BlendText properties.
obj_BlendText["extrude_base"] = 0.1
obj_BlendText["_RNA_UI"] = {"extrude_base": {"min":0.1, "max":20.0}}
obj_BlendText["bevel_reso_base"] = 1
obj_BlendText["_RNA_UI"] = {"bevel_reso_base": {"min":0, "max":16}}
obj_BlendText["font_name"] = "Arial"
obj_BlendText["use_caps"] = 0
obj_BlendText["_RNA_UI"] = {"use_caps": {"min":0, "max":1}}
Thanks Crouch, I did see a comment about that on the API site, but was not sure what it meant. Your example code clears that up. Is it possible to add the description into the RNA_UI as well? Or is that relevant for id-properties?
@Ricky: Percentage is not going to work in my case because I want to simply route the values from the properties directly to object values managed by my script. Keeping types such as float and int intact will simplify the code later on.
RickyBlender: It’s not true that you can’t change min/max/etc. values of properties after creation. It is possible. For ID-properties have a look at the example above. For RNA properties you can do it by redefining the property.
There are Scene properties, Properties global to all objects and ID-Properties (which is what I am interested in at this moment). You use different code methods to operate/create/edit these properties. I was trying to mix and match code elements from various posts without realizing that there are indeed multiple kinds of properties that the new API supports.
One of the most confusing things about properties in 2.5 is that there are different kinds of properties. That confused me until I read the page at the link under _RNA_UI at the top of this post.
i was refering more about scene properties that you define and then use let say in a panel operator button
when you do that i think it’s not possible ro redefine the min max values or to assign a value to the propertie itself !
cause it is considered out of context ID error !
but if it is possible i would definitively like to see and example of this it would be very usefull