1
$\begingroup$

In an add-on panel I have two buttons that have to call the same operator whose role is to select some mesh faces.

The only difference in execution mode is that in one case the selection is added to the already selected faces, in the other case the previous selection has to be cleared.

I could certainly code two different operators but it doesn't seem like a clean and elegant solution to me, also considering that I could implement other selection logics such as SUBTRACT, INVERT, DIFFERENCE, to the SET and EXTEND modes I mentioned above.

Is there a way to make the operator aware of which button called it or a way to pass the operator a parameter to set the operating mode?

The panel definition contains this code:

        row = box.row()
        row.label(text="Select faces")
        col = row.column()
        col.operator("object.select_faces", text="", icon='SELECT_SET')
        col = row.column()
        col.operator("object.select_faces", text="", icon='SELECT_EXTEND')

The operator should work kind of this:

class myOperator(bpy.types.Operator): 
    bl_label = "Select faces by mesh type"
    bl_idname = "object.select_faces"
    bl_options = {"REGISTER", "UNDO"}

    def execute(self, context):
        ...
        if ...op_mode_set...:       # condition to determine the operating mode
            ...clear_selection...   # execute this only if called by SELECT_SET button

        ...perform_requested_selection...     # execute always
        ...
$\endgroup$
2

0

You must log in to answer this question.

Browse other questions tagged .