1
$\begingroup$

When separating bits out of a grease pencil into a new object, Blender creates a default layer in this new object. But it leaves the layer "inactive". After that, I can't run any operators on the object. If you draw on it it creates a new layer.

I'm trying to find a way to activate that layer

and the API command that I thought would fit gives me a context error:


bpy.ops.gpencil.layer_change()
#also tried all of the enums in the following error out of desperation
...
TypeError: Calling operator "bpy.ops.gpencil.layer_change" error, expected a string enum in ('INVOKE_DEFAULT', 'INVOKE_REGION_WIN', 'INVOKE_REGION_CHANNELS', 'INVOKE_REGION_PREVIEW', 'INVOKE_AREA', 'INVOKE_SCREEN', 'EXEC_DEFAULT', 'EXEC_REGION_WIN', 'EXEC_REGION_CHANNELS', 'EXEC_REGION_PREVIEW', 'EXEC_AREA', 'EXEC_SCREEN')

My next try didn't do anything that I can see:

ob = bpy.data.objects['GPencil.003']
ob.data.layers[0].select =True

clicking on the layer in the panel echos:

bpy.context.object.data.active_index = 1

but from the VIEW_3d or terminal it gives a context error. I don't know how to force the context to that panel and I'm guessing that's a bad practice.

Is there a way to activate a greasepencil layer?

Thanks

$\endgroup$

Your Answer

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

Browse other questions tagged or ask your own question.