-2
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ Do you mean you want to make a button that add a mesh you have edited? $\endgroup$
    – 8N Films
    Apr 4 at 11:52
  • $\begingroup$ Ya, a button. Can you send the code? $\endgroup$ Apr 4 at 11:53
-1
$\begingroup$

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

$\endgroup$
3
  • $\begingroup$ 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? $\endgroup$ Apr 4 at 12:16
  • $\begingroup$ Thanks, your answer after you edited is good $\endgroup$ Apr 4 at 12:28
  • $\begingroup$ Hey, can you pls answer a question about this script? I want to know how you script after "def main(context):" My question here: blender.stackexchange.com/questions/218377/… $\endgroup$ Apr 4 at 12:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.