I'm making an attempt to use batFINGER's method from this answer for drawing some text on screen without a modal operator, but I'm finding I can't get the text to go away once it's been drawn.
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 sel_obj_1 = (int(bpy.context.selected_objects.location)) blf.position(font_id, sel_obj_1, 10, 0) blf.size(font_id, 12, 72) blf.draw(font_id, "%s %s" % (context.selected_objects, self.prop)) scene.frame_set(scene.frame_current) def remove_handle(self): bpy.types.SpaceView3D.draw_handler_remove(self.handle, 'WINDOW')
I then call the DrawingClass with a checkbox in the UI:
def get_draw_screen(self): bpy.context.scene.frame_set(bpy.context.scene.frame_current) return self["vp_draw_screen"] def set_draw_screen(self, value): context = bpy.context test = DrawingClass(context, "TURKEY PALS") self["vp_draw_screen"] = value if value: test else: test.remove_handle() bpy.context.scene.frame_set(bpy.context.scene.frame_current)
When you check the checkbox the name of the selected object will draw on screen and will update with the scene selection, but unchecking the box doesn't stop the text from drawing.
Checking the box again appears to draw a new instance on top of the previous one.
I'm guessing that each time I check the box a new instance of DrawingClass is being created, but I don't know how to access the instance again to remove them.
I've found answers explaining how to remove app handlers like this one here but can't quite figure out how to apply it to this situation.
Thanks for any help!