One thing you could try is creating separate vertex groups for each point you want to label and then using the following Python code in the script editor to get the positions for each vertex. Let me know if it works (or if it doesn't).
import bpy
import bmesh
ObjectName = "Plane"
VertexGroups = ["VGroup 1", "VGroup 2", "VGroup 3"]
obj = bpy.data.objects[ObjectName]
vGroupIndex = 0
def select_obj(obj):
obj.select_set(True)
bpy.context.view_layer.objects.active = obj
def create_cube():
bpyscene = bpy.context.scene
mesh = bpy.data.meshes.new("Vertex")
cube = bpy.data.objects.new("Vertex", mesh)
bpyscene.collection.objects.link(cube)
select_obj(cube)
bm = bmesh.new()
bmesh.ops.create_cube(bm, size=1.0)
bm.to_mesh(mesh)
bm.free()
return cube
def get_vertices_in_group(a,index):
vlist = []
for v in a.data.vertices:
for g in v.groups:
if g.group == index:
vlist.append(v.index)
return vlist
def create_boxes():
boxes = [];
for vgi in VertexGroups:
vg = obj.vertex_groups[vgi]
box = create_cube()
bpy.ops.object.constraint_add(type="COPY_LOCATION")
box.constraints["Copy Location"].target = obj
box.constraints["Copy Location"].subtarget = vg.name
boxes.append(box);
return boxes
def get_locations(boxes, should_delete):
for box in boxes:
print(" ")
print(box.name)
mat = box.matrix_local
pos = (mat[0][3], mat[1][3], mat[2][3])
print(pos)
if should_delete:
bpy.ops.object.select_all(action="DESELECT")
select_obj(box)
bpy.ops.object.delete(use_global=False)
boxes = create_boxes()
get_locations(boxes, True)
You can replace ObjectName with whatever your plane is called and VertexGroups with the list of the names of the vertex groups you end up using for each vertex.
The way it works is by creating a box for each vertex group named in the VertexGroup
list, and then using the copy location constraint to move the box over to wherever the vertex is. Then it uses the box's matrix_local
to find it's actual position (just checking the box's location doesn't take constrains into account and thus just returns (0,0,0)
)
It doesn't work to just find the vertices in the vertex groups and spit out their positions (vertex.co
) because that only gives the position of the vertex relative to the object's origin as it is in edit mode (i.e. it won't account for armature poses, constraints, or even moving the mesh in object mode)
I doubt this is the fastest or best way to do this, but hopefully it will work well enough. Hope it helps, and let me know if it works (or if it doesn't)