I have a UI panel for my addon, with a couple of buttons that should all invoke a custom operator class which append objects from another blend file.
My questions is how do I append specific object based on what specific button is pressed without making a new class (with an execute function attached) for each button.
I have a decent amount of scripting experience but classes and Blender's addon making are super mysterious to me. I know how to pass variable into functions, which is a technique I use when scripting, but have no idea how to do this within classes.
That's my ui_panel.py, which currently has one button but ultimately should have multiple buttons that append different objects from a blend file which store all my assets:
class UI_PT_Panel(bpy.types.Panel):
bl_idname = "UI_PT_Panel"
bl_label = "My Panel"
bl_category = "My Addon"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
def draw(self, context):
layout = self.layout
row = layout.row()
row.operator('wm.appending_basic_objects', text = "Append object")
And this is my append_operator.py, which should have a variable handling which object is appended based on which button is pressed in the UI (or something equivalent to that):
class Append_OT_Operator(bpy.types.Operator):
bl_idname = "wm.appending_basic_objects"
bl_label = "Append the basic objects"
def execute(self, context):
path = (r'C:/Users/')
blendfile = "Assets" + ".blend"
bpy.ops.wm.append(
filepath = blendfile,
directory = path + '/' + blendfile + "/Object/",
filename = 'my_object')
return {'FINISHED'}
Finally I have an init.py which only register and unregister classes (still have no idea what this mean but I know it's necessary).