I want to display a property in the viewport without using a modal operator. is it possible? I found this, but I did not understand how I can use (I started with python).
Asked
Active
Viewed 1,185 times
1 Answers
5
Extending the code from Draw and update text in viewport without modal operator in blender
I suggest using a class to handle the handles, and pass context to the callback method.
import bpy
import blf
class DrawingClass:
def __init__(self, context, prop):
self.prop = prop
self.handle = bpy.types.SpaceView3D.draw_handler_add(
self.draw_text_callback,(context,),
'WINDOW', 'POST_PIXEL')
def draw_text_callback(self, context):
font_id = 0 # XXX, need to find out how best to get this.
# draw some text
blf.position(font_id, 15, 50, 0)
blf.size(font_id, 20, 72)
blf.draw(font_id, "%s %s" % (context.scene.name, self.prop))
def remove_handle(self):
bpy.types.SpaceView3D.draw_handler_remove(self.handle, 'WINDOW')
context = bpy.context
dc = DrawingClass(context, "Draw This On Screen")
#dc.remove_handle() # will remove the handle and stop drawing
bpy.app.driver_namespace["foo"] = bar– batFINGER Oct 10 '17 at 14:45