3
$\begingroup$

I have a button for a modal time operator, when I press on it the modal time operator starts and the button is dimmed/disabled (as I wanted, depending on some conditions in the poll function) and everything works fine. But if I saved the file (with the button dimmed) then closed blender and opened it again the button will still be dimmed (As I wanted in the poll function) but the modal time is not running. How I can get it running? There is a certain condition in the poll function which is when it's True I want the modal timer to starts even if the button is dimmed. Any advice please?

Below is a sample code:

class modaltimeoperator(bpy.types.Operator):
        """Start modaltimeoperator"""
        bl_idname = "wm.modaltimeoperator"
        bl_label = "Start modaltimeoperator"

        _timer = None


        @classmethod
        def poll(cls, context):
                # depending on some conditions in my scene the visibility 
                #  is turned on/off. One of these conditions satisfies the 
                #  modal timer to be run again


                return on_off


        def modal(self, context, event):
                scene = context.scene


                if event.type == 'LEFTMOUSE' and event.value == 'RELEASE':
                        print('entered correct event')

                return {'PASS_THROUGH'}


        def execute(self, context):
                print('entered execute')


                wm = context.window_manager
                self._timer = wm.event_timer_add(0.1, context.window)
                wm.modal_handler_add(self)

                return {'RUNNING_MODAL'}


        def cancel(self, context):
                wm = context.window_manager
                wm.event_timer_remove(self._timer)
$\endgroup$

1 Answer 1

2
$\begingroup$

Running timers based on the file you have open can be done by defining a handler on bpy.app.handlers.load_post.

This handler can check the state of the blend file and start executing based on this.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .