0
$\begingroup$

I executed print ("test") with Blender's PythonConsle.

print("test")

Then "test" was printed in the Console as shown in the image below.

enter image description here

However, I wrote code that uses ModalOperator to execute print ("test") every second, but it was not output to the Console. Is it possible to print using ModalOperator?

import bpy

class ModalTimerOperator(bpy.types.Operator):
    bl_idname = "wm.modal_timer_operator"
    bl_label = "Modal Timer Operator"
    _timer = None
    def __init__(self):
        self.s = None
    def modal(self, context, event):
        if event.type in {'RIGHTMOUSE', 'ESC'}:
            self.cancel(context)
            return{'CANCELLED'}
        if event.type=='TIMER':
            print("test")
        return{'PASS_THROUGH'}
    def execute(self, context):
        wm = context.window_manager
        self._timer = wm.event_timer_add(1, window=context.window)
        wm.modal_handler_add(self)
        return {'RUNNING_MODAL'}
    def cancel(self, context):
        wm = context.window_manager
        wm.event_timer_remove(self._timer)

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

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

if __name__ == "__main__":
    register()

bpy.ops.wm.modal_timer_operator()

enter image description here

$\endgroup$

Browse other questions tagged or ask your own question.