Example output from my test script - It just generates a set of 5 lines in 3D space as a demo of how to use this api
For the benefit of everyone, I've included the test/demo script I wrote at the end of this post. You should be able to just copy and paste it into a text editor (fingers crossed it doesn't grab any of the HTML crap in the process) and start playing around.
Use cases for being able to create Grease Pencil strokes using Python include loading in stroke data from other apps, or for providing addon developers additional ways of adding in-viewport annotations without having to hack around with bgl and draw handlers.
# Demo script to add some gpencil points manually
# NOTE: For the context stuff to work, this should be run from an editor that can have GP data
# add points to new layer
gpl = context.active_gpencil_layer
gpl.info = "Python-Generated Demo Data"
# create new frame to host the strokes
gpf = gpl.frames.new(context.scene.frame_current)
# create some strokes
for x in range(5):
# create new stroke
stroke = gpf.strokes.new()
stroke.draw_mode = '3DSPACE'
# create the list of points - all set to defaults
# set the stroke point coordinates
for y, pt in enumerate(stroke.points):
pt.co = [x, y+1, x*y]
pt.pressure = 1.0
"""Demo operator for adding grease pencil data"""
bl_idname = "gpencil.add_data_demo"
bl_label = "GPencil API Demo"
def poll(cls, context):
return context.area and context.area.type == 'VIEW_3D'
def execute(self, context):
if __name__ == "__main__":
# test call