0

I was working with the addon but I have stuck at this situation. I want to press the Next button inside panel then, new operators should pop up and the rest operators should be removed. Basically, I want to know how does Next button work.

There is a better example in the screenshots to understand what I am looking for.

enter image description here enter image description here

import bpy
C = bpy.context
D = bpy.data
O = bpy.ops

class ADDON_PANEL(bpy.types.Panel): bl_label = "Add Objects" bl_idname = "pl.add_mesh" bl_space_type = "VIEW_3D" bl_region_type = "UI" bl_category = "Add Objects"

def draw(self,context):
    layout = self.layout
    layout.operator('meshes.delete_all')
    row=layout.row(align=True)
    row.operator('back.op')
    row.operator('next.op')

layout.operator('mesh.add_cube')

class NEXT_OP(bpy.types.Operator): bl_label = "Next" bl_idname = "next.op"

def execute(self, context):
    return {'FINISHED'}

class BACK_OP(bpy.types.Operator): bl_label = "Back" bl_idname = "back.op"

def execute(self, context):
    return {'FINISHED'}

class ADD_OBJECTS(bpy.types.Operator): bl_label = "Add Cube" bl_idname = "mesh.add_cube"

def execute(self, context):
    O.mesh.primitive_cube_add()
    C.object.modifiers.new('Subdividion','SUBSURF')
    return {'FINISHED'}


class DELETE_ALL(bpy.types.Operator): bl_label = "Delete all objects" bl_idname = "meshes.delete_all"

def execute(self, context):
    bpy.ops.object.select_all(action='SELECT')
    bpy.ops.object.delete(use_global=False, confirm=False)
    return {'FINISHED'}


classes = (ADDON_PANEL, DELETE_ALL, NEXT_OP, BACK_OP, ADD_OBJECTS) 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() ```

Muzammil
  • 828
  • 2
  • 14

1 Answers1

0

I would use a custom property for the UI to store the page number (How to create a custom UI?). The Next button increases the number and the Back button decreases it. In the draw method, use the value to decide which buttons should be shown on the given page. The property is stored in the scene.

Notes:
Beware that if there is an error in the draw method you only will see it in the System Console. There is no error popup.
If you have different independent scenes, there will be different options for your add-on in each scene.

next and back buttons

import bpy

from bpy.props import (StringProperty, BoolProperty, IntProperty, FloatProperty, FloatVectorProperty, EnumProperty, PointerProperty, ) from bpy.types import (Panel, Menu, Operator, PropertyGroup, )

C = bpy.context D = bpy.data O = bpy.ops

class ADDON_PANEL(bpy.types.Panel): bl_label = "Add Objects" bl_idname = "pl.add_mesh" bl_space_type = "VIEW_3D" bl_region_type = "UI" bl_category = "Add Objects"

def draw(self,context):
    layout = self.layout
    layout.operator('meshes.delete_all')

    my_tool = context.scene.my_tool   # access to properties

    print('draw: my_tool.wizard_page_number -> ', my_tool.wizard_page_number)

    # decide what to draw on the current page
    row=layout.row(align=True)
    if my_tool.wizard_page_number > 0:
        row.operator('back.op')
    if my_tool.wizard_page_number < 3:
        row.operator('next.op')
    if my_tool.wizard_page_number == 1:
        layout.operator('mesh.add_cube')

    layout.prop(my_tool, "wizard_page_number")    

class NEXT_OP(bpy.types.Operator): bl_label = "Next" bl_idname = "next.op"

def execute(self, context):
    my_tool = context.scene.my_tool   # access to properties
    my_tool.wizard_page_number += 1   # next page
    return {'FINISHED'}

class BACK_OP(bpy.types.Operator): bl_label = "Back" bl_idname = "back.op"

def execute(self, context):
    my_tool = context.scene.my_tool   # access to properties
    my_tool.wizard_page_number -= 1   # prev. page
    return {'FINISHED'}

class ADD_OBJECTS(bpy.types.Operator): bl_label = "Add Cube" bl_idname = "mesh.add_cube"

def execute(self, context):
    O.mesh.primitive_cube_add()
    C.object.modifiers.new('Subdividion','SUBSURF')
    return {'FINISHED'}


class DELETE_ALL(bpy.types.Operator): bl_label = f"Delete all objects" bl_idname = "meshes.delete_all"

def execute(self, context):
    bpy.ops.object.select_all(action='SELECT')
    bpy.ops.object.delete(use_global=False, confirm=False)
    return {'FINISHED'}

------------------------------------------------------------------------

Scene Properties

------------------------------------------------------------------------

class MyProperties(PropertyGroup):

wizard_page_number: IntProperty(
    name="Wizard Page Number",
    description="Current Page of the Wizard",
    default = 0
    )

------------------------------------------------------------------------

classes = (ADDON_PANEL, DELETE_ALL, NEXT_OP, BACK_OP, ADD_OBJECTS, MyProperties) # register MyProperties def register(): for cls in classes: bpy.utils.register_class(cls) bpy.types.Scene.my_tool = PointerProperty(type=MyProperties) # store in scene

def unregister(): for cls in classes: bpy.utils.unregister_class(cls) del bpy.types.Scene.my_tool # delete from scene

if name == "main": register()

Blunder
  • 13,925
  • 4
  • 13
  • 36