I would like to add a slider to my own panel. How can i do that and how can i then read the value from it and assign it to a variable? I already tried this:

row.prop(bpy.props.FloatProperty(name="maxdist", description="test", default=3.0, min=0.0, max=10.0, soft_min=0.0, soft_max=10.0, step=1, precision=1, unit='NONE', update=None, get=None, set=None))

And i get this error: TypeError: UILayout.prop(): error with argument 1, "data" - Function.data expected a AnyType type, not tuple

What am i doing wrong?

Thanks, Nebeig


To edit a value in a panel, the value needs to be a property of an item, such as the scene or object. You use bpy.props to add new properties to existing classes. For example :-

bpy.types.Object.myprop = bpy.props.FloatProperty()

You can then display that property in a panel. You add the slider=True option to have it display as a slider.

row.prop(context.object, 'myprop', slider=True)
  • $\begingroup$ When i try to read value from the slider with bpy.context.object.myprop and then use that value in another pyhton file (via import from) it says : RecursionError: maximum recursion depth exceeded. $\endgroup$ – Nebeig Jul 30 '18 at 13:30
  • $\begingroup$ You don't import the bpy.context.object.myprop from another script. Both scripts have import bpy and directly read bpy.context.object.myprop. $\endgroup$ – sambler Jul 30 '18 at 18:45
  • $\begingroup$ oh, yes that did the trick for me. Thank you $\endgroup$ – Nebeig Jul 31 '18 at 8:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.