Grease Pencil Vertex Group Weight per Points

Hi everyone !

I hope I’m posting on the right section :slight_smile:

I’m working on a Grease Pencil Add-On and I was wondering if it was possible to get the vertex group weight of each points of a grease pencil stroke ?

For what I found, a “weight” attribute is available in the stroke.groups[i].weight but return only one value :hushed: And the strokes[i].points[i] doesn’t seems to have anything related to a vertex group.

Otherwise, the solution of going through the data.vertex_groups[i].weight() with points indexes fail also because I can’t get the point.index.

Anything I’m missing ?

Thanks in advance for your answers,

Issue has been fixed by Antonio, thanks to him :pray: ! (for Blender 2.93)

Here’s the example code he gave :

import bpy
ob = bpy.context.active_object
gpd = ob.data
gps = gpd.layers[0].frames[0].strokes[0]
i = 0
print("Weights\n================================")
for pt in gps.points:
gps.points.weight_set(vertex_group_index=0, point_index=i, weight=0.5)
i +=1

i = 0
for pt in gps.points:
weight = gps.points.weight_get(vertex_group_index=0, point_index=i)
print(weight)
i +=1

I was digging into that and I noticed that if there is no weight assigned to the Vertex Group it will throw an error. Do you guys have way to check if the vertex group has no elements assigned to it?

What I did was just a Try : before the weight_get :
try: weight = gps.points.weight_get(vertex_group_index = group.index, point_index=j) except : weight = 0

Also in a specific case where I wanted to copy-paste weight from an actual Mesh, I used a loop to set each vertice with a weight of 0 at first to be sure that it won’t throw exception.

Hi Pierre,
thanks for the answer. I didn’t want to use a try, but I guess in this case I have no other choice :frowning: