Hi;
I’m trying to create a custom property through code, but just can’t get to how to adjust the min and max values. The documentation is so vague Here’s my code:
bpy.types.Object.foo = bpy.props.FloatProperty()
ob.foo = 0
Hi;
I’m trying to create a custom property through code, but just can’t get to how to adjust the min and max values. The documentation is so vague Here’s my code:
bpy.types.Object.foo = bpy.props.FloatProperty()
ob.foo = 0
It’s in fact very simple :
bpy.types.Object.foo = bpy.props.FloatProperty(min=0.1, max=10.0)
A tip I often use : in the text editor, look at the python templates, there are a lot of codes you can use in order to understand things like this. Or in the python console, you can type a method or constructor (like bpy.props.FloatProperty) and use completion (ctrl+space) to display a small doc which list the arguments of the method and what they mean. Quite useful.
Thanx Kevar, I really appreciate it… And thanx for the tip as well, well noted
Cheers;
AJ
There’s also soft_min and soft_max, which will be respected for mouse input. min and max are considered on text input.
Hello,
I just wonder if it’s possible to change a parameter value of a property (more specifically the soft_min and soft_max values) after the property have been created?
I’ve tried to do this:
bpy.types.Scene.SliderWireThickness = bpy.props.FloatProperty(name='Wire Thickness', subtype='FACTOR',
precision=3,
soft_min=0.001,
soft_max=5,
update=update_wire_thickness)
bpy.types.Scene.SliderWireThickness[1]['soft_min'] = 1.0
bpy.types.Scene.SliderWireThickness[1]['soft_max'] = 2.0
But I’m not sure what it changes, because when it draws the slider in the UI it’s still soft_min=0.001 and soft_max=5. If you can’t change these values I could go with having 3 different sliders to cover up for the 3 different presets I want.
Thanks.
You can’t adjust them after creation. It is on my wish list and have mentioned to devs…
Using set/get or update methods you can control the values but it doesn’t give the same nice feedback.
Hmm, how do you do it with set/get or update? I have tried to do it with update, when I select one item from a drop-down list the Slider is supposed to get updated but it doesn’t. I might be misunderstanding you.
Thank you anyways! :yes:
here’s how to do it in blender 3.1
lod_prop = "LOD"
control_object[lod_prop] = 1
id_props = control_object.id_properties_ui(lod_prop)
id_props.update(min=0,
max=2,
)
control_object.property_overridable_library_set('["LOD"]', True)
What I did was to register / unregister the property on the TYPE (curves, in my case). Then, on any new curve I added to the scene, the property was already attached. I could easily access it in my panel UI like any blender property.
def register():
bpy.types.Curve.my_property = bpy.props.IntProperty(
name = "My Property",
default = 12,
min = 2,
max = 128
)
def unregister():
bpy.types.Curve.my_property
Then, in the “draw” function of my panel code
def draw(self, context):
col = layout.column()
if context.object is not None:
col.prop(context.object.data, 'my_property')
This gave me the slider with the min and max enforced. However, the propeerty didn’t appear in the “custom properties” section of the object panel until I actually changed the property with the slider (some kind of refresh problem).
for area in bpy.context.screen.areas:
if area.type == 'PROPERTIES':
area.tag_redraw()