0
$\begingroup$

I am trying to add a custom property to my panel. The custom property should look like the ones for scaling the object (sliding bar).

Here below my code so far. As you can see, I managed to implement the property for scaling the object and provide a name. The thing is that for such properties, it seems like there is already a pre-defined property that can be called using row.prop(obj, 'name') and row.prop(obj, 'scale'). But what about if I want to add a custom property (float) called "my_property"?

import bpy # Python API for Blender
from bpy.types import Panel, Operator


# Class for the panel, derived by Panel
class ADDONNAME_PT_main_panel(Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_label = 'new_tab'
bl_context = 'objectmode'
bl_category = 'new' # Where the Panel have to appear. In this case in the Tools cetegory.

# Add UI elements here
def draw(self, context):
    layout = self.layout

    # New row
    row = layout.row()

    # get the selected object
    obj = context.object

    #Add scale slider property
    row = layout.row()
    row.prop(obj, 'scale', index=0, text='Scale x:')

    row = layout.row()
    row.prop(obj, 'scale', index=1, text='Scale y:')

    row = layout.row()
    row.prop(obj, 'scale', index=2, text='Scale z:')
    
    row = layout.row()
    row.prop(obj, 'name')
    
    

   classes = [ADDONNAME_PT_main_panel]



   def register():
   for cls in classes:
    bpy.utils.register_class(cls)
    

   def unregister():
   for cls in classes:
    bpy.utils.unregister_class(cls)
   

   if __name__ == "__main__":
   register()
$\endgroup$
1

Your Answer

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

Browse other questions tagged or ask your own question.