INFO Box dissappears for running modal operator that uses pass though #102939

Closed
opened 2022-12-04 11:50:42 +01:00 by Ioanna Marinou · 4 comments

System Information
Operating system: Have tried both MAC &WINDOWS
Graphics card: Various

Blender Version
Broken: 3.1

I'm trying to make a blender addon that will work as a timer so I can easier keep track of how much time I'm spending on a project. I've tried various approaches the best one I've found this far is to have a simple button on my UI that when clicked will trigger the following function:

class ModalOperator(bpy.types.Operator):
    bl_idname = "object.modal_operator"
    bl_label = "Simple Modal Operator"
    
    _timer = None
    def __init__(self):
        print("Start")
        self.counter = 0

    def __del__(self):
        print("End")

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

    def modal(self, context, event):
        if event.type == 'TIMER':
            self.counter +=1
            self.report({'INFO'}, 'Counter:' + str(self.counter))
        return {'PASS_THROUGH'}

    def invoke(self, context, event):
        self.execute(context)

        self._timer = context.window_manager.event_timer_add(1, window=context.window)
        context.window_manager.modal_handler_add(self)
        return {'RUNNING_MODAL'}

the counter will be replaced by time difference when the following problem gets sorted. This approach partially works but if there is a 3d object with active (not applied modifiers) and try to reorder them the info box that was initially visible at the bottom of blender disappears and no matter what I do only reappears if I restart blender. I've tried clicking the button that starts the fuction again. Also after adding print statments I realised that the operator is still running and the problem is that the info box is not showing up. Finally, if I change pass_through to running_moodal blender does not allow me to interact with it at all

**System Information** Operating system: Have tried both MAC &WINDOWS Graphics card: Various **Blender Version** Broken: 3.1 I'm trying to make a blender addon that will work as a timer so I can easier keep track of how much time I'm spending on a project. I've tried various approaches the best one I've found this far is to have a simple button on my UI that when clicked will trigger the following function: ``` class ModalOperator(bpy.types.Operator): bl_idname = "object.modal_operator" bl_label = "Simple Modal Operator" _timer = None def __init__(self): print("Start") self.counter = 0 def __del__(self): print("End") def execute(self, context): return {'FINISHED'} def modal(self, context, event): if event.type == 'TIMER': self.counter +=1 self.report({'INFO'}, 'Counter:' + str(self.counter)) return {'PASS_THROUGH'} def invoke(self, context, event): self.execute(context) self._timer = context.window_manager.event_timer_add(1, window=context.window) context.window_manager.modal_handler_add(self) return {'RUNNING_MODAL'} ``` the counter will be replaced by time difference when the following problem gets sorted. This approach partially works but if there is a 3d object with active (not applied modifiers) and try to reorder them the info box that was initially visible at the bottom of blender disappears and no matter what I do only reappears if I restart blender. I've tried clicking the button that starts the fuction again. Also after adding print statments I realised that the operator is still running and the problem is that the info box is not showing up. Finally, if I change pass_through to running_moodal blender does not allow me to interact with it at all
Author

Added subscriber: @marinouj

Added subscriber: @marinouj

Added subscriber: @iss

Added subscriber: @iss

I am no python expert, but seems weird to declare __init__ and __del__ for operator. I can confirm strange behavior though, with my script, timer will increase frequency and print(self.counter) is never executed. Also operator then can't be stopped. I think I have seen similar report, seems like there is conflict with timer being used for another operation.

This seems to be broken for quite a long time, see blender/blender#98892.

Perhaps you could store start time in custom property and produce report every x seconds when timer is in broken state. I suspect that report does not show up because of frequency of these reports. Alternative could be to use app handlers, but there you can't guarantee any periodicity. But registering on frame change, on save and on render should produce relatively frequent calls. Maybe with on save handler will run with autosave feature, and you can set period of that in preferences.

I am no python expert, but seems weird to declare `__init__` and `__del__` for operator. I can confirm strange behavior though, with my script, timer will increase frequency and `print(self.counter)` is never executed. Also operator then can't be stopped. I think I have seen similar report, seems like there is conflict with timer being used for another operation. This seems to be broken for quite a long time, see blender/blender#98892. Perhaps you could store start time in custom property and produce report every x seconds when timer is in broken state. I suspect that report does not show up because of frequency of these reports. Alternative could be to use app handlers, but there you can't guarantee any periodicity. But registering on frame change, on save and on render should produce relatively frequent calls. Maybe with on save handler will run with autosave feature, and you can set period of that in preferences.

Closed as duplicate of blender/blender#98892

Closed as duplicate of blender/blender#98892
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#102939
No description provided.