2
$\begingroup$

I need to list the extremities of an edge. I've got a selected edge in edit mode and I need to list the coordinates. This will be very useful!

This because I'm looking for the rotation of an edge on the XY plane. I've already figured out how to get the angle but I need the two vertices coordinates to start the math. Hope there is a built-in method!

Thank you for your attention.

$\endgroup$

2 Answers 2

2
$\begingroup$

This will display the coordinates of the selected vertices of the selected object ( you have the local and the world coordinates as @poor have noted )

import bpy

obj = bpy.context.object
bpy.ops.object.mode_set(mode = 'OBJECT')
#all selected vertices indecies
verts_ind = [i.index for i in obj.data.vertices if i.select]
bpy.ops.object.mode_set(mode = 'EDIT')

for i in verts_ind :
    local_co = obj.data.vertices[i].co
    world_co = obj.matrix_world * local_co
    print(world_co)
$\endgroup$
3
  • 1
    $\begingroup$ You are too fast :) What about obj.matrix_world * obj.data.vertices[i].co? $\endgroup$
    – p2or
    Mar 24, 2015 at 14:37
  • $\begingroup$ Thank you both for the world coordinates. The local_co will also be useful. $\endgroup$
    – isar
    Mar 24, 2015 at 15:17
  • $\begingroup$ with blender 2.8 need to replace * by @ world_co = obj.matrix_world @ local_co $\endgroup$
    – Penbeuz
    May 13, 2020 at 11:17
0
$\begingroup$

Bmesh module variant, which does not require a mode change:

import bpy
import bmesh

ob = bpy.context.object
me = ob.data
bm = bmesh.from_edit_mesh(me)

mat = ob.matrix_world

for edge in bm.edges:
    if edge.select:
        print("Edge {}\n".format(edge.index))
        for vert in edge.verts:
            print("  Vertex {}:".format(vert.index))
            print("    ", vert.co, "local")
            print("    ", mat * vert.co, "global\n")
        break

Note that above code works in edit-mode only, but it's also possible to extend it with support for object mode.

$\endgroup$

You must log in to answer this question.

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