Basic code for adding floatproperty to panel in 2.80

I’ve been trying to port an old add on I made, that uses a floatproperty in a panel. I made the recommended changes and changed the = to a : but I’m still confused on some of the syntax and scope of the class. Does anyone have basic code that adds a FloatPropery (and the widget) into a panel? I couldn’t find any in the code templates. Thanks.

Normally, you just add a layout.prop to the panel’s draw function, and point to the source of that prop.

def draw(self, context):
     self.layout.prop(source_object, property_name)

For example prop(bpy.context.scene, 'frame_current')
(i know, it’s not a Float… but it works the same) :slight_smile:

I appreciate it, but I need a working code example. Sometimes the floatproperty is created as a class propetry in your custom class, other times it’s defined in an init function called by register(). sometimes it’s put in a separate propertygroup class… I’d love the basic code for an add on that creates either (a checkbox/boolproprty, or a float widget/floatproperty) inside a panel, or whatever.

I don’t think you can add properties to ‘Panels’, they are not part that is saved in a blend file…

Anyway, this works:

import bpy

class VIEW3D_PT_testpanel(bpy.types.Panel):
    bl_label = "testpanel"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    bl_category = "testpanel"
    def draw(self, context):
        layout = self.layout
        layout.prop(bpy.context.scene, 'myfloat')

def register():
    bpy.types.Scene.myfloat = bpy.props.FloatProperty(name="myfloat", default=0.5)

def unregister():
    del bpy.types.Scene.myfloat

if __name__ == "__main__":
1 Like

Thank you very much, @Secrop that’s exactly what I was looking for.