Selected points

I select in the editor N points which are connected by edges (or are not connected)…
How in a script to receive co-ordinates of the selected points (x, y, z) and to find out what of them are connected?

Here a heap of experts! I do not believe, that nobody knows… Same it is not difficult!
Help me!

You need to grab the mesh and then loop through the vertices checking them for the selection flag:

import Blender
from Blender import Mesh

selectedVerts = []

me = Mesh.Get('MyMesh')

for v in me.verts:
     if v.sel == 1:

WARNING: this code was written on the fly. It is untested.

So this script will loop through the vertices in the mesh MyMesh, check if they are selected, and if they are, it writes the vertexes index (what you can use to get the information from the vertices later). You could also change v.index to to pull out the vector of its coordinates.

To test for edge connectivity, you can roughly do this, again untested, and probably not the best way of doing this:

for ed in me.edges:
     for i in selectedVerts:
          for j in selectedVerts:
               if (min(i,j), max(i,j)) == ed.key:
                    #The vertices are connected, do your processing

This is a very inefficient way of doing this, but it should work. Note that it relies on selectedVerts containing the indices of the vertexes.

If I can work out the more efficient way Ill post it (or somebody else will).

you can also use the function “selected()”:
vsel = mesh.verts.selected()
it returns a list of all the selected vertices
and to get co-ordinates:

v_others = [[] for i in xrange(len(me.verts))]
for ed in me.edges:
  if ed.sel:
# now you have a list of other verts, aligned to each vert 
for v in me.verts:
  print "my selected brothers", v,  v_others[v.index]

2 all: many thanks!

How to add a item to menu Specials “w”?