I would like to be able to extract start and end points of grease pencil line tool, the one used for annotations in 2.80.

It would be great if I can get the data in 3d view and 2d screen view in Python.



Grease Pencil (GP) data structure is like this:

GP-Object --> GP-Layers --> GP-Frames --> GP-Strokes --> GP-Stroke-Points

Now, the python commands to get different GP-data,

#1) To get the GP-Object data  
GPObj = bpy.data.objects['GP Object Name'].data

#2) To get the GP-layers, use layer name or index.
GPLyr = GPObj.layers['Layer Name']

#3) To get the GP-Frames, use index. But there are other properties of the layer
#   you can access e.g., opacity, thickness, select, etc. You can add or remove the frame.
GPFrm = GPLyr.frames[0]

#4) To get the GP-strokes, use index. You can add or remove a stroke, change the
#   display-mode, line-width, material index, etc. 
GPStk = GPFrm.strokes[0]

#5) To get the GP-points, you can use the index to get individual points.
#   You can add or remove points. 
GPPts = GPStk.points

and each point has info about the location, pressure, strength, uv-rotation, etc. With the help of "foreach_get()" function, you can get the location (or pressure, strength, uv-rotation) of all the points.

#6) To get the location of single GP-point
loc = GPPts[0].co

Use the grease pencil API:


Drill down through the layers and frames and strokes to get to the points:


  • $\begingroup$ Thanks but I am looking for basic code to crack that. It is a bit of abstract to me now. $\endgroup$
    – yarun can
    Jun 5 '19 at 4:25

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.