2
$\begingroup$

I have an add-on that I want to use as a Workspace Tool (similar to the Bevel Tool). How can I set up my operator's modal call to only run the operator once and simply adjust the operator's property when the user moves the mouse left or right? I'd like behavior similar to the Redo Panel where the state is reverted every time the property is adjusted. My operator adds points to the object and adjusts them based on the operator's radius property. Currently points are being added with every mouse move which isn't good. Thank you!

    first_mouse_x: IntProperty()
    first_value: FloatProperty()

    def modal(self, context, event):
        if event.type == 'MOUSEMOVE':
            delta = self.first_mouse_x - event.mouse_x
            my_operator(self,context,self.first_value + delta * 0.01) #how can I reset the state with every mouse move?

        elif event.type == 'LEFTMOUSE':
            return {'FINISHED'}

        elif event.type in {'RIGHTMOUSE', 'ESC'}:
            my_operator(self,context,self.first_value)
            return {'CANCELLED'}

        return {'RUNNING_MODAL'}
$\endgroup$
2
  • 1
    $\begingroup$ that's a really good question and i hoped for an answer as well. But as far as i understood the workflow up to now (i might be wrong) that's not possible and you have to "rebuild" the mesh yourself each time. $\endgroup$
    – Chris
    Commented Feb 9, 2023 at 4:54
  • 1
    $\begingroup$ If I understand the question correctly, you could save some data to a global variable on the first call, or bpy.ops.ed.undo_push() is also a good option. $\endgroup$
    – X Y
    Commented Feb 9, 2023 at 5:22

0

You must log in to answer this question.

Browse other questions tagged .