5
$\begingroup$

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.

thanks

$\endgroup$

2 Answers 2

14
$\begingroup$

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
$\endgroup$
1
  • $\begingroup$ Is it possible to select all GP-strokes in one GPStk obj? I want to get all objects in GPFrm.strokes. not only the first GPFrm.strokes[0] $\endgroup$
    – nammerkage
    Mar 31 at 14:30
0
$\begingroup$

Use the grease pencil API:

https://docs.blender.org/api/current/bpy.types.GreasePencil.html

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

https://docs.blender.org/api/current/bpy.types.GPencilStrokePoints.html

$\endgroup$
1
  • $\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, 2019 at 4:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .