getting both verts from edge

I got another question, I need to get the vertices from an edge. I can get to the MeshEdge object.

http://www.blender.org/documentation/250PythonDoc/bpy.types.MeshEdge.html#bpy.types.MeshEdge.vertices

How do I use that, I try with mesh.edges.vertices, but It comes up with an error. Also tried mesh.edges.vertices().

#solved first question about groups
Hi, I’m trying to get all the verts from a VertexGroup in blender 2.5.

I managed to get the VertexGroup object, but where do I go from there? Is there a certain property? I get errors if I try to use it like a list.
http://www.blender.org/documentation/250PythonDoc/bpy.types.VertexGroup.html

In 2.49, there was a simple function for mesh objects mesh.getVertsFromGroup(group). This doesn’t work in 2.5 anymore.

I don’t know if this will work in 2.5, but I’m working on a simple exporter in 2.49, here’s the function that I set up for listing the vertex groups and thier centers.


def dump_vgroups(mesh_ob_name):
 mesh_ob = Blender.Object.Get(mesh_ob_name)
 mesh = mesh_ob.getData (mesh=True)
 print '<vgroups>'
 for name in mesh.getVertGroupNames():
  print '	<name = ',name,'/>'
  vertlist = mesh.getVertsFromGroup(name)
  avgx = 0
  avgy = 0
  avgz = 0
  count = 0
  for vert in vertlist:
   count += 1
   avgx += mesh.verts[vert].co.x
   avgy += mesh.verts[vert].co.y
   avgz += mesh.verts[vert].co.z
  print '	<center = ',avgx/count, ',', avgy/count, ',', avgz/count,'/>'
 print '</vgroups>'

This works with Blender 2.53 rev. 31550

import bpy

def listVertexGroups(ob):
    if not (ob and ob.type == 'MESH'):
        print("Not a mesh: %s" % ob)
        return
        
    me = ob.data        
    vertGroups = {}
    for vgrp in ob.vertex_groups:
        vlist = []
        for v in me.vertices:
            for vg in v.groups:
                if vg.group == vgrp.index:
                    vlist.append((v.index, vg.weight))
        vertGroups[vgrp.name] = vlist
    return vertGroups
    
vertGroups = listVertexGroups(bpy.context.object)
for (key, value) in vertGroups.items():
    print(key, value)
    

sorry it does work in 315 but in 626 it’s ok
cause of API change!

i get error on line 13 that there no vertices in 316?
must change vertices for verts!

Thanks

Thanks Thomas works great, and yeah, had to change it to verts.

I got another question, I need to get the vertices from an edge. I can get to the MeshEdge object.

http://www.blender.org/documentation/250PythonDoc/bpy.types.MeshEdge.html#bpy.types.MeshEdge.vertices

How do I use that, I try with mesh.edges.vertices, but It comes up with an error. Also tried mesh.edges.vertices().

like this :yes:


import bpy
cubedata = bpy.context.active_object.data
alledges = cubedata.edges.values()
edge4 = alledges[4]
v1,v2 = edge4.vertices
print(v1,v2)
print(cubedata.vertices[v1].co)

Default blender active object is the Cube …
Result:
1 5
Vector((1.0, -1.0, -1.0))

Thanks, it’s not vertices though, it’s verts, documentation had it wrong.

Version problem sinds 31… verts has become vertices again (so you have an (too?!) old version?! :wink: )