2
$\begingroup$

i want to iterate through every single vertex of an object and then store them in a list.

what I have so far is:

for mesh in object.meshes:
   for m_index in range(len(mesh.materials)):
      for v_index in range(mesh.getVertexArrayLength(m_index)):

         vertex = mesh.getVertex(m_index, v_index)

now i understand that "v_index" gets me "vertex 0 through 23" of the object (its a cube), but how can i store the result in a list?

vertex_list(0,1,2,3,4...23)

thanks for any hint,

sputi

$\endgroup$
  • $\begingroup$ what i want to do ist to simultaneously shift vertices 0-3 and 4-7 by an X value so that the shape don't breaks. $\endgroup$ – Sputi Sep 17 '15 at 12:28
2
$\begingroup$

While not blender specific, it is a basic python list operation. Start by creating an empty list, then append each item.

verts = []
for mesh in object.meshes:
    for m_index in range(len(mesh.materials)):
        for v_index in range(mesh.getVertexArrayLength(m_index)):
            verts.append(mesh.getVertex(m_index, v_index))

You may also want to adjust them as you go instead of making a list.

posadjust = [0,1,2,3]
negadjust = [4,5,6,7]
for mesh in object.meshes:
    for m_index in range(len(mesh.materials)):
        for v_index in range(mesh.getVertexArrayLength(m_index)):
            if v_index in posadjust:
                vertex = mesh.getVertex(m_index, v_index)
                vertex.x += 0.2
            elif v_index in negadjust:
                vertex = mesh.getVertex(m_index, v_index)
                vertex.x -= 0.2
$\endgroup$
  • $\begingroup$ thank you, very helpful! However they are in a strange order... how do I know which vertex is where on my cube?? $\endgroup$ – Sputi Sep 23 '15 at 20:20
  • $\begingroup$ By looking at them in edit mode. How to view and sort them is explained here. $\endgroup$ – sambler Sep 24 '15 at 5:12
  • $\begingroup$ I've already read that to completion, however it only explains how to see the order of the INDEX (one number per corner) and not of the VERTEX (3 numbers per corner, 3 vertices from 3 faces... ). I always seem to get the same answer that doesn't really help me - Or do I get something completely wrong here?? $\endgroup$ – Sputi Sep 24 '15 at 7:41
  • $\begingroup$ kind of a solution: blenderartists.org/forum/… $\endgroup$ – Sputi Sep 24 '15 at 17:44
  • 1
    $\begingroup$ @Sputi a vertex has one index which is it's position in the list of vertices. One vertex can have many edges connected to it, that is edge 1,3,6 and 7 can all connect to vertex 4. A face is then surrounded by a list of edges with vertices at each corner. When displaying the indices in the 3dview only the selected items will be shown, which is based on the selection type/s chosen. $\endgroup$ – sambler Sep 28 '15 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.