All possible callbacks
Prints to console when callbacks fired
So much info in the python console, autocomplete on draw handler add. Will see that args
is a tuple of arguments passed to the callback method. Error in question was passing 1 arg to a method with none. Will show up in system console as an error.
>>> bpy.types.SpaceView3D.draw_handler_add(
draw_handler_add(callback, args, region_type, draw_type)
.. method:: draw_handler_add(callback, args, region_type, draw_type)
Add a new draw handler to this space type.
It will be called every time the specified region in the space type will be drawn.
Note: All arguments are positional only for now.
:param callback:
A function that will be called when the region is drawn.
It gets the specified arguments as input.
:type callback: function
:param args: Arguments that will be passed to the callback.
:type args: tuple
:param region_type: The region type the callback draws in; usually ``WINDOW``. (:class:`bpy.types.Region.type`)
:type region_type: str
:param draw_type: Usually ``POST_PIXEL`` for 2D drawing and ``POST_VIEW`` for 3D drawing. In some cases ``PRE_VIEW`` can be used. ``BACKDROP`` can be used for backdrops in the node editor.
:type draw_type: str
:return: Handler that can be removed later on.
:rtype: object
Attempt to add every draw call back possible. Has to be a redraw of the type specified to fire the callback. I doesn't relentlessly fire.
import bpy
from bpy.types import SpaceView3D, Region
class DrawClass:
def __init__(self, context):
print("INIT")
for rt in Region.bl_rna.properties['type'].enum_items.keys():
for d in ('POST_PIXEL', 'POST_VIEW', 'PRE_VIEW', 'BACKDROP'):
try:
SpaceView3D.draw_handler_add(
self.dcb, (rt, d,), rt, d)
except:
print("No dcb for", rt, d)
def dcb(self, rt, d):
print("Testing dcb:", rt, d)
if __name__ == "__main__":
DrawClass(bpy.context)
(context,)
is the argument(s) being passed to the callback method. You have defined the method with no other argumentsdef draw_callback(self)
it's one or the other, pass no arguments or declare them in method defn. $\endgroup$()
which I assume is the right syntax for no arguments in python. But the code still doesn't produce any output from the print function. $\endgroup$context.area.tag_redraw()
to update every frame. $\endgroup$