2
$\begingroup$

I would like to run 2 actions with a custom button. For example in edit mode I would like to run 1. Disolve edges and after that, 2. Disolve vertex.

Is there a way to create this custom button?

Thank you.

$\endgroup$
  • $\begingroup$ By "button", do you mean a keyboard shortcut or a clickable button in the interface? $\endgroup$ – gandalf3 Nov 17 '14 at 6:57
5
$\begingroup$

Too add custom buttons to the UI here in 3D view / Toolpanel you could something like this:

import bpy

class DissolvePanel(bpy.types.Panel):
    bl_label = "Dissolve Panel"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'TOOLS'

    def draw(self, context):
        layout = self.layout
        col = layout.column(align=True)
        row = col.row(align=True)
        row.operator("mesh.dissolve_edges", text = "Dissolve Edges")
        row.operator("mesh.dissolve_verts", text = "Dissolve Verts")
        # invoke custom operator
        # row.operator("object.simple_operator" , text = "All")

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

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

if __name__ == "__main__":
    register()

To run dissolve edges followed by dissolve vertices you would need to define your own operator, to enable the All button uncomment this line in the above script:

# row.operator("object.simple_operator" , text = "All"):

Custom operator (from editor's templates)

import bpy


def main(context):
    bpy.ops.mesh.dissolve_edges()
    bpy.ops.mesh.dissolve_verts()

class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"

    @classmethod
    def poll(cls, context):
        return context.active_object is not None

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

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

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

if __name__ == "__main__":
    register()
    # test call
    bpy.ops.object.simple_operator()
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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