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")
groups[0].weight
Is not one attribute.weight
is an attribute ofgroups[0]
. $\endgroup$