1
$\begingroup$

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
bpy.ops.gpencil.editmode_toggle()

# select all vertices (doesn't work)
bpy.ops.gpencil.select_all(action="SELECT")

# 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).

$\endgroup$
1
  • $\begingroup$ This looks like it "should" work. Can show how to get and set the points of a grease pencil's stroke using the API. $\endgroup$ – batFINGER Oct 26 '20 at 12:03
1
$\begingroup$

To do with API methods

As commented, the code used looks like it "should" work. Have answered showing a low level alternative to move the gp data points.

Move all points of all strokes of all frames of all layers of the gp object's data.

Narrow down using active frame or layer if required.

import bpy
from mathutils import Vector
from bpy import context

ob = context.object

gp = ob.data
active_layer = gp.layers.active
active_frame = active_layer.active_frame
for layer in gp.layers:
    for frame in layer.frames:
        for stroke in frame.strokes:
            for p in stroke.points:
                p.co += Vector((0.5, 0, 0))

Selecting via operator appears to need 3D view area for context.

Can select all the gp data via operator, by overriding the context to include the 3D view area, eg

import bpy

# assume is in EDIT mode
for a in bpy.context.screen.areas:
    if a.type == 'VIEW_3D':

        # select all vertices (doesn't work)
        bpy.ops.gpencil.select_all(action="SELECT")
        # run in 3d area or override context to "pretend" in 3d area works.
        bpy.ops.gpencil.select_all({"area" : a}, action="SELECT")
        break

However the transform translate operator, on attempts so far, always returns cancelled. Any attempt to override causes death to blender.

$\endgroup$

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.