Method to understand the logical path in the API documentation

Hi developers,

often get stuck while navigating in the API doc.

Example:

bpy.ops.gpencil.draw --> Doc says (…) stroke (bpy_prop_collection of OperatorStrokeElement, (optional)

So I go to :
OperatorStrokeElement
There, I can read:
class bpy.types.OperatorStrokeElement(PropertyGroup)
is_start / type boolean,default False
location …
etc …

But, where can I find the correct syntax for the stroke parameter ?
What are the required parameters of that stroke since the doc doesn’t mention optional or not?
The doc doesn’t explain what is the meaning of the parameter, i.e is_start …

So I go for:
stroke = [
and then { or ( or [ ??
location= or “location”: …) ??

In the console I use autocomplete, helps going further for knowing the methods that can be applied, but not about the parameters of those …
As well, if I go for dir (OperatorStrokeElement) in the console, what are the methods/modules displayed ? I cannot use them in the Python API or am I wrong ?

So what is the correct way of using that API documentation ?

Thanks for any help !
SF

OperatorStrokeElement is not an operator and has thus no parameters. It is a PropertyGroup which has properties.

What the GPencil operator accepts is a CollectionProperty of the type OperatorStrokeElement. All of the properties are defined, although you don’t need to set them (they will remain at their default value in this case).

If you want to create gpencil strokes with python, don’t use operators:

import bpy

ob = bpy.context.object

gp = bpy.data.grease_pencil.new("GPencil")
ob.grease_pencil = gp
    
gp.draw_mode = 'VIEW'
layer = gp.layers.new("GP_Layer", set_active=True)

frame = layer.frames.new(bpy.context.scene.frame_current)
stroke = frame.strokes.new()

stroke.draw_mode = '3DSPACE'
points = stroke.points
points.add(2)

points[0].co = (0, 0, 0)
points[0].pressure = 1.0

points[1].co = (0, 0, 3)
points[1].pressure = 1.0

Thanks once again CodeMan !
That code suits well for my application.

Danke.

Just for future reference, if you want help understanding how an operator works in Blender here is one method.

  • Goto the ‘Scripting’ screen layout.
    • You will see that the ‘info’ panel at the top is expanded so you can see the menu and also text displayed below it.
  • Manually do the operation that you would like to duplicate in the 3D view.

You will see that in the extra space in the ‘info’ window, Blender outputs the call to bpy.ops that you just executed by hand. You can see how Blender uses the op and what parameters it is passing to them.

Thanks ! That’s a fine thing. I didn’t know.

SF