Python API + Grease Pencil + Vertex Group

477/5000

Hello everyone.
I am new to Blender Python API. I want to create via Python Vertex Groups with the points of the last stroke that is of the last layer of a Grease Pencil Object.
First I developed a script that worked with the vertices of a MESH. It worked.
When I went to adapt the code to the Grease Pencil Object, it did not operate correctly. The Code in Python created the layers but did not add the points, as in the Mesh object.
What’s wrong?
Thnx
Cristiano

Code:

import bpy
gp_obj=bpy.context.active_object
vcont = 0
cont = 0
name_vg = "bone" + str(cont)
gp_obj.vertex_groups.new(name=name_vg)
arr = []
if(gp_obj.type == 'MESH'):
    for v in gp_obj.data.vertices:    
        arr.append(vcont)
        print(arr)
        vcont = vcont + 1
        if ((vcont % 5) == 0):
            gp_obj.vertex_groups[name_vg].add(index = arr,weight = 1,type = 'ADD')
            #vcont = 0
            arr = []
            cont = cont + 1
            name_vg = "bone" + str(cont)
            gp_obj.vertex_groups.new(name=name_vg)        
        gp_obj.vertex_groups[name_vg].add(index = arr,weight = 1,type = 'ADD')
if(gp_obj.type == 'GPENCIL'):
    print("\nGPENCIL")
    stroke = gp_obj.data.layers.active.active_frame.strokes[len(gp_obj.data.layers.active.active_frame.strokes)-1]
    pontos = stroke.points
    for v in pontos:
        arr.append(vcont)
        print(arr)
        vcont = vcont + 1
        if ((vcont % 20) == 0):
            gp_obj.vertex_groups[name_vg].add(index = arr,weight = 1,type = 'ADD')
            #vcont = 0
            arr = []
            cont = cont + 1
            print(str(cont)+" ***************************** ")
            name_vg = "bone" + str(cont)
            gp_obj.vertex_groups.new(name=name_vg)        
        gp_obj.vertex_groups[name_vg].add(index = arr,weight = 1,type = 'ADD')