1
$\begingroup$

My problem: I need to execute a code after an operator has finished.

The operator is a non modal operator with the UNDO option to show the operator menu with its properties. I know that technically is not being executed, is executed once.

My objective is to call that code when the undo panel dissappears (I'm doing some gizmos drawing and I want them to stop drawing when the menu goes away). But despite the execute is called once, I want them to remain being drawn while the operator's menu is drawn.

(With undo panel, I mean the panel that is shown right after executing some operators:)

enter image description here

At the moment, I have a pretty bad solution I don't like a single bit:

  • A timer that basically checks when the active operator has changed:

      def check_operator_has_finished_timer():
    
          active_operator = bpy.context.active_operator
    
          if active_operator is None or isinstance(active_operator, My_OT_class) == False:
              unregister_drawing_handlers() # This simply unregisters the drawing gizmos
              return None
    

The problem with that is:

  • It continuous running after the OT's menu has gone. unregister_drawing_handlers() is only called when I trigger a different operator manually in the UI (basically something that overrides bpy.context.active_operator)

Ideas I had in mind (but not sure if they are possible and how (thats why I'm asking)):

  • I thought about iterating all panels in the UI (not sure if Blender allows that), and I guess that maybe that way I could tell if the OT's undo panel is on. (and if the panels is not thre, I call my unregister_drawing_handlers()).

(Any different idea would be appreciated. I'm still a newbie and I don't know if maybe I'm missing a basic method that is automatically called when the OT is finished and I'm missing something trivial).

Thank you so much for reading and for any help, much appreciated :)

$\endgroup$
2
  • 1
    $\begingroup$ Hello ! AFAIK there is no way to differentiate when an operator is first called and when it is re-run due to the redo panel, nor when the redo panel is closed. You'd have to resort to hacky workarounds I'm afraid. $\endgroup$
    – Gorgious
    Dec 16, 2023 at 14:31
  • $\begingroup$ Hello Gorgious! Much appreciated as always friend, at least is good to know that is not possible hehe. Time to embrace a more creative approach :] $\endgroup$
    – Ommadawn
    Dec 16, 2023 at 16:14

0

You must log in to answer this question.

Browse other questions tagged .