2
$\begingroup$

I am new to scripting with python in Blender. I want to get the coordinates of a vertex (x, y, z) from the transform sidebar in Blender with python script and print it out in the system console.

How can I access the transform sidebar with python scripting?

x y z of vertex in transform panel sidebar

$\endgroup$
2
  • $\begingroup$ You probably want to access the data displayed there, not the sidebar. It might be helpful to provide more context as well. Why do you need this? What are you trying to do? $\endgroup$ Nov 3, 2023 at 6:11
  • $\begingroup$ I'm trying to replicate segment button functionality of calculating distance between two selected vertices of measure-it addon $\endgroup$
    – nikhil
    Nov 4, 2023 at 6:43

1 Answer 1

3
$\begingroup$

The values in the panel are not accessible via Phyton because they are calculated depending on the selected geometry. You can make the calculation yourself using the following script:

import bpy
from mathutils import Vector

obj = bpy.context.active_object
if obj and obj.type == "MESH" and bpy.context.mode == 'EDIT_MESH':
    if obj.data.total_vert_sel > 0:
        obj.update_from_editmode() 
        verts_sel = [v.co for v in obj.data.vertices if v.select]
        median_local = sum(verts_sel, Vector()) / len(verts_sel)
        median_global = obj.matrix_world @ median_local                        
        print("Global:", tuple(median_global))
        print("Local:", tuple(median_local))
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .