1
$\begingroup$

I'm currently writing an addon for blender 2.8 which requires the creation of strokes using the grease pencil. I've tried the stroke programming described by other forums but it doesn't allow me to make use of the grease pencils' brush options.

stroke =  scene.collection.objects["GPencil"].data.layers["Outline"].active_frame.strokes.new()

Hence I'm trying to use the draw operator of the grease pencil to create a realistic "hand-drawn" effect but the operator isn't doing anything despite producing no errors!

bpy.ops.gpencil.draw(mode='DRAW', stroke = stroke, wait_for_input=False, disable_straight=False, disable_fill=False, guide_last_angle=0.0)

My code:

stroke = [{"name": "defaultStroke",
                "mouse" : (527.0, 330.0),
                "pen_flip" : False,
                "is_start": True,
                "location": (2, 0, 10),
                "pressure": 1.0,
                "time": 1.0,
                "size": 20.0
                }]

    strokeLength = len(processedVertices)

    for i in range (0, strokeLength):
        #converts coordinates from local to global 
        point = head.matrix_world @ processedVertices[i]

        stroke.append({ "name": "defaultStroke" + str(i),
                    "mouse" : (527.0, 330.0),
                    "pen_flip" : False,
                    "is_start": False,
                    "location": (point[0], point[1], point[2]),
                    "pressure": 1.0,
                    "time": 1.0,
                    "size": 20.0
                    })


area = bpy.context.area
old_type = area.type
area.type = 'VIEW_3D'

bpy.ops.gpencil.paintmode_toggle(back=False)

bpy.ops.gpencil.draw(mode='DRAW', stroke = stroke, wait_for_input=False, disable_straight=False, disable_fill=False, guide_last_angle=0.0)

area.type = old_type
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.