Cant get the "Add modifier" button to show up

Hello, I need some help again with my createion panel. Now I have come to adding modifier part, but whatever I do I cant get the “add modifier” button to show up. Heres my entire script so far:

import bpy




class LayoutDemoPanel(bpy.types.Panel):
    """Adds  a panel in the right toolbar in the scene context for creating and edit objects"""
    bl_label = "Create"
    bl_idname = "SCENE_PT_layout"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "scene"


    def draw(self, context):
        layout = self.layout


        scene = context.scene



    def draw(self, context):
        layout = self.layout

        rd = context.scene.render

        row = layout.row(align=True)
        row.operator("render.render", text="Render", icon='RENDER_STILL')

         #Add cube 
        row = layout.row()
        props = row.operator("mesh.primitive_cube_add", text="Cube")


        del row


        #Add sphere
        row = layout.row()
        props = row.operator("mesh.primitive_uv_sphere_add", text="Sphere")


        del row




        #Add cynlinder
        row = layout.row()
        props = row.operator("mesh.primitive_cylinder_add", text="Cylinder")


        del row
        
        
        
    
        
        
         #Add light 
        row = layout.row()
        layout.operator_enum("object.lamp_add", "type")
        del row
        
        
        
        
        #Add camera
        row = layout.row()
        props = row.operator("object.camera_add", text="Camera",)
        

       
        del row
        
        #Change to object or edit mode
        layout.template_header_3D()
        row = layout.row()
        if obj:
            mode = obj.mode
            # Particle edit
            if mode == 'PARTICLE_EDIT':
                row.prop(toolsettings.particle_edit, "select_mode", text="", expand=True)
                
                
        
        #Add modifiers
        row = layout.row()
        layout.operator_menu_enum("object.modifier_add", "type")

        for md in ob.modifiers:
            box = layout.template_modifier(md)
            if box:
                # match enum type to our functions, avoids a lookup table.
                getattr(self, md.type)(box, ob, md)
                del row
        
        
        



def register():
    bpy.utils.register_class(LayoutDemoPanel)


def unregister():
    bpy.utils.unregister_class(LayoutDemoPanel)


if __name__ == "__main__":
    register()

Looking at your code, you never define obj. That errors in line 80, so nothing after that will run, including your modifier button.

Thanks for your reply. So how do I fix that?

You need to insert:


obj = bpy.context.active_object

this part will give you problems as well, because you have ob instead of obj:


 for md in ob.modifiers:
            box = layout.template_modifier(md)
            if box:
                # match enum type to our functions, avoids a lookup table.
                getattr(self, md.type)(box, ob, md)
                del row

Just change each instance of ob to obj. Also i think this line: layout.template_header_3D() isn’t going to work outside the 3D View.

Thanks for your help again :slight_smile: All I tried to do was to create a panel on the right side, so I didnt have to use the vertical tabs. But this guy solved it with this awezome addon: https://blenderartists.org/forum/showthread.php?414384-Blender-tabs-Interface-Clean-and-fast-blender-UI . /Case solved