F
by falken10vdl on 12 Mar 2025, edited 13 Mar 2025
#
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!
M
by Moult on 12 Mar 2025
#
+2 votes
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.
F
by falken10vdl on 13 Mar 2025, edited 13 Mar 2025
#
@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
M
by Moult on 13 Mar 2025
#
What if you just detect local view https://blender.stackexchange.com/questions/51854/how-can-i-detect-global-local-view-via-python in the grid decorator?
I'm also wondering whether it even is a good idea to hide grids in local view. What about other decorators, like solar analysis? Or georeferencing?
F
by falken10vdl on 13 Mar 2025
#
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!
G
by Gorgious on 13 Mar 2025
#
+1 votes
Just to iterate I would not try to mess with operators, you should be able to know if a 3D viewport is in local view with https://docs.blender.org/api/current/bpy.types.SpaceView3D.html#bpy.types.SpaceView3D.local_view