Why is the underlying command of "select all" not working when executed with python? (Grease Pencil)


while in edit mode of a grease pencil object, the tooltip of “select all” says that the corresponding python command would be bpy.ops.gpencil.select_all(action='SELECT').
This is also confirmed by the Info Editor.

But when I try to run this command while in edit mode (either from the Python Console or in a script), it doesn’t select anything.

For example this code doesn’t work (if the vertices weren’t already selected):

import bpy

# change to edit mode

# select all vertices (doesn't work)

# move the selected vertices
bpy.ops.transform.translate(value=(-0.5, 0, 0), orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', mirror=True, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False) 

What am I doing wrong?

I use blender 2.90.1 (same behavior occurred in blender 2.91.0 Alpha).

I’ve also posted this question on blender stackexchange.

Best regards

I’ve noticed when working in the driver graph editor, the select all command there needed to be called in the graph window itself. You may need to have your script commands called from the 3d View.

When you’re running commands like this from the text editor, it could be assuming you’re selecting all grease pencil vertices in the text editor, which there are none. The same when running them in the python console.

So you’ll prob need to place your commands in a class, register (and unregister) the class, and either have your class drawn in one of the 3d view menus, panels as a link or install your script as an addon and create a keymap (under 3D View section ) for it, to be called directly.