Hi, I want to set the minimum/maximum value for a FloatProperty which is exposed to the UI as a slider dynamically. However, I am not able to get this to work. The following code should do the following: - the first slider defines a (lower) limit - the second slider shall be a value, but it must not be smaller than the limit set in the first slider. It will create the following UI:
Attached is the code. It willl create a new tab in the Tools menu. The value will now always be 0.00, even though the setter and getter are called. You may also want to have a look here: https://blender.stackexchange.com/questions/18686/setting-a-propertys-min-and-max-values-after-creation
import bpy import os class View3dPanel(): bl_space_type="VIEW_3D" bl_region_type="TOOLS" bl_category="MyTool" class ValueOperator(bpy.types.Operator): bl_idname = "bpt.boulder_wall_start_height" bl_label = "todo" def showValue(self, context): print("in showValue", context.scene.value) def getter(self): print("in getter", self['value']) return self["value"] def setter(self, value): print("in setter", value) if value < bpy.context.scene.limit: print("value too small") return None class MyPanel(View3dPanel,bpy.types.Panel): bl_label="MyPanel" def draw(self,context): layout=self.layout #layout.operator(operator = "dh.simple_opt",text = "Add Cube & Cone",icon = "OUTLINER_DATA_LAMP") col=layout.column(align = True) col.prop(context.scene, "limit") col.separator() col.prop(context.scene, "value") def register(): bpy.utils.register_class(MyPanel) bpy.utils.register_class(ValueOperator) def unregister(): bpy.utils.unregister_class(MyPanel) bpy.utils.unregister_class(ValueOperator) if __name__=='__main__': os.system('cls') bpy.types.Scene.limit = bpy.props.FloatProperty(name = "lower limit", default = 0, min = 0, max = 255, description = "lower limit for value slider") bpy.types.Scene.value = bpy.props.FloatProperty(set = ValueOperator.setter, get = ValueOperator.getter, name = "value", default = 1, min = 0, max = 255, description = "value, cannot be less than lower limit", update = ValueOperator.showValue) register()
Any hint is greatly appreciated. blackno666