OSArch Community

Can a blender addon intercept a blender function?

  1. F

    I was looking to open issues and looked to this one:

    [If local view is toggled, that it turns off grid decorations. #6257

    ](https://github.com/IfcOpenShell/IfcOpenShell/issues/6257 "If local view is toggled, that it turns off grid decorations. #6257

    ")

    Is it possible for a blender addon to intercept a blender function?

    If it is possible, do you know where in Bonsai one can register a callback function for such action?

    Thanks!

  1. M

    Short answer no. You cannot trigger or override another operator (especially built-in).

    There are way around it though, you can create your own operator and override the hotkey instead and place it in the menu next to the built-in function. Or you can check for certain things in a decorator. Or a depsgraph update handler. Or certain properties can be subscribed using the msgbus (like active object).

    That bug is probably erroneously marked as first time contributor because it's probably a bit trickier to know how to detect this state.

  1. F

    @Moult said:

    Short answer no. You cannot trigger or override another operator (especially built-in).

    There are way around it though, you can create your own operator and override the hotkey instead and place it in the menu next to the built-in function. Or you can check for certain things in a decorator. Or a depsgraph update handler. Or certain properties can be subscribed using the msgbus (like active object).

    That bug is probably erroneously marked as first time contributor because it's probably a bit trickier to know how to detect this state.

    Understood. I have taken a look to some examples within the Bonsai source code and come up with something to create the operator.

    I have filled a PR for it ( If local view is toggled, that it turns off grid decorations. #6257 #6335 ). I do not know if these are the right places:

    • Operator class under src/bonsai/bonsai/bim/operator.py

    • A menu entry in src/bonsai/bonsai/bim/ui.py below the BIM_PT_snappping(Panel):

    • Registration/unregistration of the new operator under src/bonsai/bonsai/bim/init.py. (overriding the hotkey as you suggested)

    As a side effect, if nothing is selected the shortcut provides a fast way to toggle the grid decorations on/off

  1. M
  1. F

    I agree, probably the operator view3d.localview_custom should not override the hotkey. In fact a hotkey to toggle the grid is just one click away from #6257 and probably a simple solution.

    Anyhow, thanks a lot for explaining the possibilities regarding operators and hotkeys!

  1. G

Login or Register to reply.