-3

I want to make a button in my panel to add mesh that has been edited. I have edited the mesh with modifiers and some others things. When I press that button, it would like to add a mesh that I have edited.

8N Films
  • 163
  • 1
  • 12

1 Answers1

-1

To make a button that adds a mesh you have edited, you need to make an operator. You need to type def main(context): and type what you edit on the mesh. Operator script:

class OperatorName(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "operator_id_name"
    bl_label = "label_of_operator"
def execute(self, context):
    main(context)
    return {'FINISHED'}```

Here is an add-on script that I am working on, example for this question:

def main(context):
    bpy.ops.mesh.primitive_monkey_add()
    bpy.ops.object.modifier_add(type='SUBSURF')
    bpy.context.object.modifiers["Subdivision"].levels = 4

class SmoothMonkey(bpy.types.Operator): """Tooltip""" bl_idname = "mesh.smooth_monkey" bl_label = "Add Smooth Monkey"

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

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

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

if __name__ == "__main__":
register()

# test call
# bpy.ops.mesh.smooth_monkey()

To use this operator, you need to type

row = layout.row()
row.operator("mesh.smooth_monkey", icon= 'MONKEY', text= "Add smooth monkey")

after def draw(self, context): your panel script

8N Films
  • 163
  • 1
  • 12
  • Then how can I add this script into my panel script? That means how can I use this operator in my panel to make a button? – Doggy is best Apr 04 '21 at 12:16
  • Thanks, your answer after you edited is good – Doggy is best Apr 04 '21 at 12:28
  • Hey, can you pls answer a question about this script? I want to know how you script after "def main(context):" My question here: https://blender.stackexchange.com/questions/218377/how-can-i-know-scripts-of-what-i-am-editing-on-mesh – Doggy is best Apr 04 '21 at 12:41