0

How to display various and custom info text in viewport with script and clean with another script and /or shortcut in blender 2.8+(im using 2.9).

SCRIPT FOR DISPLAY

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
dns = bpy.app.driver_namespace dns["dc"] = DrawingClass(context, "Draw This On Screen")

SCRIPT FOR CANCEL TEXT DRAW

import bpy
dns = bpy.app.driver_namespace
dc = dns.get("dc")
dc.remove_handle()
  • Hi! Bare minimum is to show some effort (research, code, minimal example etc.). Please read: https://blender.stackexchange.com/help/how-to-ask – brockmann Jul 23 '20 at 18:24
  • Also https://blender.stackexchange.com/questions/135123/display-text-on-3d-viewport – batFINGER Jul 23 '20 at 20:00
  • need the clear script. in this question and other ther'arent the script for clear in 2.8+ –  Jul 23 '20 at 21:31
  • Please take your time and try to explain in detail: what you got and what you'd like to achieve by editing your question. – brockmann Jul 24 '20 at 08:29
  • @batFINGER The question this is marked as duplicate of may have a duplicate answer, but it is not a duplicate question. – Ray Mairlot Jul 24 '20 at 12:45
  • 1
    @RayMairlot It's good enough AFAIC. OP deleted prior question after it was marked as a dupe of question their illustration came from re centering text on screen. . Hence OP is aware of code to write text on screen. If OP can explain why the answer to question marked as dupe doesn't work for them yeah perhaps re-open. At the moment it shows very little effort (the other close vote above) . Will attempt to hunt down a better dupe. – batFINGER Jul 24 '20 at 12:56
  • @batFINGER I don't think we should be closing questions based on what an OP has demonstrated they know in other questions. If other people come across this question and get directed to the duplicate I don't think they will find the answer explanatory enough of this problem. – Ray Mairlot Jul 24 '20 at 13:02
  • 1
    @RayMairlot Somehow (due to me too) original dupe comes from https://blender.stackexchange.com/questions/135123/display-text-on-3d-viewport chose to cut out middle man. The second one re middle of the viewport is the OP's previous question (self removed) after marked dupe One I perhaps could have used as primary dupe again. Do we need a question for bottom left, top left, slightly left of center, there is one re using 3d coords. – batFINGER Jul 24 '20 at 13:41
  • @batFINGER It's certainly getting a bit confusing, I would say this (again, duplicate answer, not question) and this are not good duplicates, the other two are. – Ray Mairlot Jul 24 '20 at 15:27
  • 1
    @batFINGER I don't think different alignments requires different questions as those would be very similar. Would suggest just adding other alignment options to brockman's answer (if you or brockman have time) and maybe edit the question to something more general like "How do I align modal draw text in the viewport?" so it is not focused on 'middle'. Thoughts? – Ray Mairlot Jul 24 '20 at 15:27
  • you have a method for cancel text after few seconds? –  Jul 24 '20 at 19:41
  • Good approach... What's wrong with that? – brockmann Jul 24 '20 at 20:10
  • We should re-discuss that for python questions specifically. If you look around, python q/a got usually less votes but answering is much more labor intensive than 95% of all the non-python answers (like instructions how to press 3 buttons). To prevent re-iterating the same thing over and over again and also to respect the effort of the original authors -> updating the old answers and closing when the answer nails it or the OP shows no effort is the way to go IMO @RayMairlot – brockmann Jul 24 '20 at 20:22

0 Answers0