# foreach_get/set a mesh vertex group data?

I'm searching how to batch set/get vertex group data inside blender. using foreach_get() foreach_set() function from bpy.data.objects[0].data.vertices & numpy for a fast calculation.

but it seem that those two function only accept really simple properties? and batch actions on vertex_groups/vcol are not possible in blender ?

this code below is throwing me errors

vertices[...]' elements have no attribute 'groups[0].weight'

but this error message is False the elements does have this attribute !!

note that this error message also occur with getattr() and setattr()

import bpy
import numpy as np

def print_weight(o, vg_name, use_modifiers=True):

#eval object modifiers to mesh?
if use_modifiers:
depsgraph = bpy.context.evaluated_depsgraph_get()
eo = o.evaluated_get(depsgraph)
ob = eo.to_mesh(preserve_all_data_layers=True, depsgraph=depsgraph)
else: ob = o.data

"""
#slow method
weight_values = []
for v in ob.vertices:
weight_values.append( v.groups[o.vertex_groups[vg_name].index].weight )
"""
#trying fast batch_get method, unsuccessful..
weight_values = np.zeros((len(ob.vertices) * 3), dtype=np.float, )
i = o.vertex_groups[vg_name].index
ob.vertices.foreach_get(f"groups[{i}].weight", weight_values, )

print(weight_values)
return

print_weight(bpy.context.object,"Group")

• Incorrect assumption. groups[0].weight Is not one attribute. weight is an attribute of groups[0]. Nov 10, 2020 at 12:41
• oh, of course ! then i assume there's no way to quickly batch get those properties, sad Thanks for the answer
– DB3D
Nov 10, 2020 at 12:44
• Don't think so since it will also be a task to size the flat array to populate. Related blender.stackexchange.com/questions/135152/… Nov 10, 2020 at 12:47
• May also be of interest blender.stackexchange.com/questions/75223/… Nov 10, 2020 at 13:24

• I really need this patch lol. I see that the foreach_set/get patches got approved fast, could this be rewritten the same way to get it approved faster?