I'm completely baffled by this - it makes no sense to me at all!
I'm trying to copy over vertex coordinates from an object in blender into a list, and at the end of the loop the entire list is filled with only the last vertex.
This prints out the list with only the last vertex in every part of the list:
import bpy
current_obj = bpy.context.active_object
verts_l = [v.co for v in current_obj.data.vertices.values()]
verts_w = [current_obj.matrix_world * v_local for v_local in verts_l]
vert_list = [[None, None, None]] * vert_count
def build_vert_list ():
for i, vert in enumerate(verts_w):
vert_list[i][0] = verts_w[i][0]
vert_list[i][1] = verts_w[i][1]
vert_list[i][2] = verts_w[i][2]
print(vert_list)
However, if I instead print out the vert_list during the loop, it prints out the correct data:
def build_vert_list ():
for i, vert in enumerate(verts_w):
vert_list[i][0] = verts_w[i][0]
vert_list[i][1] = verts_w[i][1]
vert_list[i][2] = verts_w[i][2]
print(vert_list[i])
If I do instead:
def build_vert_list ():
for i, vert in enumerate(verts_w):
vert_list[i] = verts_w[i]
it works properly, and I can access the values in the list with vert_list[1][0] for example, however every member of list is headed with some weird nonsense, which prevents me from doing round() functions on the data.
Can anyone help me? This has me pretty stumped.
(I only started learning Python a few days ago, so go easy on the technical stuff please.)