I had an addon that set weights to Grease Pencil points using the function “weight_set” of the points collection of the stroke, in this way:
stroke.points.weight_set(vertex_group_index=group.index, point_index=i, weight=weight)
With the new Grease Pencil I’ve found that strokes are inside the “drawing” object, but the points collection has no weight_set function anymore.
How can I set the weight of a vertex group for a Grease Pencil point? There is the obj.vertex_groups[“Group_Name”].add([point_index], weight, ‘REPLACE’) function, but it’s not clear what point_index to use, because indexes restart from 0 on each stroke.
UPDATE: I’ve managed to write the weights using attributes, in this way:
attr = drawing.attributes.get(“Group”)
attr.data[stroke_offset + point_idx].value = weight
The first weird thing is that the drawing attribute must be explicitly created, even if the vertex group is created. If I create the vertex group in python, I can see it in the GP object properties, but the above code does nothing. If I create ALSO the drawing attribute, after the vertex group, then the assignment above works.
In this way when I go in Weight Paint mode I can correctly see the weights I set.
But the armature doesn’t work: even if the GP object is parented to the armature, has the armature modifier and all the groups for the bones are in place with their weights, the armature does not move the GP strokes. Even if I close and reopen the file.
In Blender 4.2 I don’t have this wrong behavior. Is there something I’m missing about setting vertex groups in grease pencil 3?
You’re creating a generic attribute instead of writing to a vertex group.
There’s a PR that will add this functionality again. See #127216 - Grease Pencil: Allow setting vertex group weights directly on a GreasePencilDrawing - blender - Blender Projects
1 Like