I'm working on a feature which needs to be a modal that runs when you're painting a stroke. It then needs to repeat that stroke again.

For this I'm trying to store the coordinates of the mouse when painting and drawing the strokes when the mouse is lifted up again.

My problem is that the modal function doesn't seem to run while the mouse is being held down. Here's the code:

class LP_OT_RepeatStroke(bpy.types.Operator):
    bl_idname = "layer_painter.repeat_stroke"
    bl_label = "Repeat Stroke"
    bl_description = "Repeats the last stroke for all channels that have a value set"
    bl_options = {"REGISTER", "UNDO_GROUPED"}

    drawing: bpy.props.BoolProperty(default=False)

    def __init__(self):
        self.coordinates = []

    def paint(self):
        for coordinate in self.coordinates:
                "time": 0,
        self.coordinates = []
        return {'FINISHED'}

    def modal(self, context, event):
        if event.type == 'LEFTMOUSE':
            if event.value == 'PRESS' and not self.drawing:
                self.drawing = True
        elif event.type == "MOUSEMOVE":
            if event.value == 'RELEASE' and self.drawing:
                self.drawing = False
        elif event.type == "ESC":
            return {"FINISHED"}
        elif self.drawing:
        return {'PASS_THROUGH'}

    def invoke(self, context, event):
        return {'RUNNING_MODAL'}

Your Answer

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

Browse other questions tagged or ask your own question.