I have several vertex groups separated on my 3D model and I would like to export the spreadsheet that reflects the x,y, and z data along with the vertex groups data. I have already been able to export only the x,y, and z data as a .csv file using a code I found on here. However, I haven’t been able to find any solutions to export the table shown below of the vertex groups. In this example listed below, I would want to export the area of the table with ‘Ears’, ‘Mouth’, ‘Eyes’, and ‘Face’ as a .csv file as well with the vertices.
The code that I have tried from Blender artists iceythe Kaoi can be found at: How do I Export an Object's Vertex Positions? - #16 by KickAir_8P
- I was to successfully export the vertices themselves in csv form but not the corresponding vertex group information.

- ^^ The table I would like to export
import bpy
import os
def write_verts():
obj = bpy.context.object
if obj is None or obj.type != "MESH":
return
# Output geometry
obj_eval = obj.evaluated_get(bpy.context.view_layer.depsgraph)
filepath = "vertices.csv"
with open(filepath, "w") as file:
# Write the header, pos x | pos y | pos z
file.write("pos x,pos y,pos z\n")
for v in obj_eval.data.vertices:
# ":.3f" means to use 3 fixed digits after the decimal point.
file.write(f",".join(f"{c:.3f}" for c in v.co) + "\n")
print(f"File was written to {os.path.join(os.getcwd(), filepath)}")
if __name__ == "__main__":
write_verts()
- ^^The code from iceythe Kaoi that I have used.
Does this help? It gives you a way to check if a vertex is part of a group (weight is set) and then you can deal with the weight value and add it to your CSV.
import bpy
GROUP_NAME="Group"
obj=bpy.context.active_object
data=obj.data
verts=data.vertices
for vert in verts:
i=vert.index
try:
weight = obj.vertex_groups[GROUP_NAME].weight(i)
#if we get past this line, then the vertex is present in the group
print(weight)
except RuntimeError:
# vertex is not in the group
pass
Copied from here: https://blender.stackexchange.com/a/65052
I am able to get pull up the weights for each group using the code you suggested, thank you. However, I am still having a hard time incorporating your suggestion into the current code to receive the weight values for each vertex. I am able to export all of the vertices labeled as x,y, and z but not the corresponding weight values for the vertex groups.
I have attached screenshots below. Do you have any suggestions on what I am doing wrong in my pipeline?
Code: Your suggestion + Code for vertices and exporting to .csv
import os
import bpy
def write_verts():
GROUP_NAME="Ears"
obj=bpy.context.active_object
data=obj.data
verts=data.vertices
if obj is None or obj.type != "MESH":
return
obj_eval = obj.evaluated_get(bpy.context.view_layer.depsgraph)
filepath = ("monkeygroups.csv")
with open(filepath, "w") as file:
file.write("pos x, pos y, pos z, Ears, Mouth, Eyes, Face\n")
for v in verts:
i=v.index
try:
weight = obj.vertex_groups[GROUP_NAME].weight(i)
file.write(f",".join(f"{c:3f}" for c in v.co) + "\n")
print(weight)
print(f"File was written to {os.path.join(os.getcwd(), filepath)}")
except RuntimeError:
pass
if name == “main”:
write_verts()
Resulting .csv from running script
I think you are missing the line where the vertex weights are supposed to be written to the file?
The line
file.write(f",".join(f"{c:3f}" for c in v.co) + "\n")
only writes the vertex coordinates. If you want to have more you would need to add the value of the vertex weight as well, e.g. something like:
file.write(f",".join(f"{c:3f}" for c in v.co) + f" {weight}"\n")
One more comment:
This try/except approach was a demo only. for multiple vertex groups I would do something like this which also solves the problem, that vertices that are not part of the vertex group get no weight value. In the snippet below the value zero is assigned to them. Storing the data + writing the CSV is outsourced to Numpy which is great for such things.
import os
import bpy
import numpy as np
GROUP_NAMES=["Ears", "Eyes", "Mouth"]
filepath = (r"d:\monkeygroups.csv")
obj=bpy.context.active_object
data=obj.data
verts=data.vertices
# if you want to use all vertex groups assigned to the object
all_group_names = [group.name for group in obj.vertex_groups]
nb_verts = len(verts)
coord_weight_array = np.zeros((nb_verts, 3+len(GROUP_NAMES)))
xyz_coord = np.empty(nb_verts * 3, dtype=np.float64)
verts.foreach_get("co", xyz_coord)
coord_weight_array[:,:3] = np.reshape(xyz_coord, (nb_verts, 3))
for group_idx, this_group in enumerate(GROUP_NAMES):
array_col = group_idx + 3
for vert_idx, v in enumerate(verts):
try:
weight = obj.vertex_groups[this_group].weight(v.index)
coord_weight_array[vert_idx, array_col] = weight
except Exception:
pass
header_str = ";".join(["pos x", "pos y", "pos z"] + GROUP_NAMES)
np.savetxt(filepath, coord_weight_array, delimiter = ';', fmt='%.8e', newline='\n', header=header_str)
This worked perfectly! Thank you for your suggestions