# How can I show the vertex positions in viewport?

I want to show some Info in the viewport something like vertex indices

you can see select a vertex and press N to see vertex position but it's hard.

so I liked to write a script to show the vertex position

I tried to use opengl but text was blurry and I couldn't make what I want.

# import stand alone modules
import blf
import bpy

font_info = {
"font_id": 0,
"handler": None,
}

def init():
"""init function - runs once"""
import os
# Create a new font object, use external ttf file.
# Store the font indice - to use later.
if os.path.exists(font_path):
else:
# Default font.
font_info["font_id"] = 0

# set the font drawing routine to run every frame
draw_callback_px, (None, None), 'WINDOW', 'POST_VIEW')

def draw_callback_px(self, context):

"""Draw on the viewports"""
# BLF drawing routine
font_id = font_info["font_id"]
#blf.position(font_id, pos.x, pos.y, pos.z)
#blf.size(font_id, 100,100)
#blf.draw(font_id, "Hello World")

pos = bpy.context.object.location
v3d = context.space_data
rv3d = v3d.region_3d
pos_text = location_3d_to_region_2d(region, rv3d, context._center)

blf.position(font_id, pos_text[0], pos_text[1], 0)
blf.size(font_id, 100,100)
blf.draw(font_id, "Hello World")

if __name__ == '__main__':
init()

• Related blender.stackexchange.com/questions/139831/… Suggest this could be marked as dupe of blender.stackexchange.com/questions/137816/… If you are sourcing code from elsewhere add a link for context. – batFINGER Sep 3 at 23:31
• @batFINGER thank you it's what I want. I just want to show text in 3d viewport I'm wondering why I didn't find that post because I searched a lot! – Seyed Morteza Kamali Sep 4 at 4:32
• @batFINGER I edited my question based on links that you sent me but I don't know why I can't see text in the viewport!!! – Seyed Morteza Kamali Sep 4 at 4:59
• Convert 3d global coords to region coords. The global location of an object is always ob.matrix_world.translation which may or may not be ob.location See blender.stackexchange.com/questions/6155/… New edit are passing None as context argument, yet trying to use it, which will throw errors to console. – batFINGER Sep 4 at 5:33

Well, you are passing no context

(None, None)


but then using some context in draw_callback_px that is None

you should use POST_PIXEL because it isn't 3d

bpy.types.SpaceView3D.draw_handler_add(draw_callback_px, (bpy.context, None), 'WINDOW', 'POST_PIXEL')


you forgot to import location_3d_to_region_2d libraries

import bpy
from bpy_extras.view3d_utils import location_3d_to_region_2d


Go to Window > Open System Console and you will see all the errors so you can have something to debug what is happening there

### convert coordinates from vertex to world-space

Multiply the world matrix by the object-space vector for world space coordinate:

import bpy

ob = bpy.data.objects['Cube']

v = ob.data.vertices[0].co
mat = ob.matrix_world

# Multiply matrix by vertex
loc = mat @ v


import blf
import bpy
from bpy_extras.view3d_utils import location_3d_to_region_2d

def draw_callback_px(context, dummy):
ob = bpy.data.objects['Cube']

v = ob.data.vertices[0].co
mat = ob.matrix_world

# Multiply matrix by vertex
pos = mat @ v

v3d = context.space_data
rv3d = v3d.region_3d
pos_text = location_3d_to_region_2d(context.region, rv3d, pos)

blf.position(0, pos_text[0], pos_text[1], 0)
blf.size(0, 1,1)
blf.draw(0, str(pos))


• Good one you got there in the end. Note using me.vertices will most likely not work as expected in edit mode if you start moving them. Check out blender.stackexchange.com/a/160913/15543 – batFINGER Sep 4 at 21:00