Hello,
Can anyone help me understand where the vertex group weights attributes are in the Grease Pencil API? I know 4.5 will have vertex_group_assign
but I’m working with 4.4 and can’t get or set these weights anywhere. It’s not documented or in dir
/help
. Thank you!
import bpy
C = bpy.context
frame = C.object.data.layers.active.current_frame()
drawing = frame.drawing
def get_global_point_index(drawing, stroke_index, point_index):
"""
Add the stroke’s curve_offset to the local point index
so you end up with the unified “global” point index.
"""
offset_value = drawing.curve_offsets[stroke_index].value
return int(offset_value) + point_index
def get_bone_weight(drawing, bone_name, stroke_index, point_index):
"""
Look up a FLOAT attribute by name on the point-domain,
and return its .value (or 0.0 if it doesn’t exist).
"""
global_idx = get_global_point_index(drawing, stroke_index, point_index)
attr = drawing.attributes.get(bone_name)
if not attr:
return 0.0
return attr.data[global_idx].value
# now loop and print
for stroke_idx, stroke in enumerate(drawing.strokes):
for pt_idx, pt in enumerate(stroke.points):
w0 = get_bone_weight(drawing, "Bone", stroke_idx, pt_idx)
w1 = get_bone_weight(drawing, "Bone.001", stroke_idx, pt_idx)
print(f"Stroke {stroke_idx:2d}, Pt {pt_idx:2d} → Bone = {w0:.4f}, Bone.001 = {w1:.4f}")
The vertex group weights for “Bone” and “Bone.001” show in the Spreadsheet for the Control Points, but don’t show any values with my script.
Thank you!