4
$\begingroup$

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

$\endgroup$
0

1 Answer 1

7
$\begingroup$

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)
$\endgroup$
3
  • $\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
    Commented Jul 30, 2018 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
    Commented Jul 30, 2018 at 18:45
  • $\begingroup$ oh, yes that did the trick for me. Thank you $\endgroup$
    – Nebeig
    Commented Jul 31, 2018 at 8:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .