user: Show practical ways to work with Layers in a Blender add-on or script – include code.

assistant: # Layers

[image reference removed]

Grease Pencil Layers panel.

Grease Pencil objects can be organized into a tree known as the layer tree for grouping and arranging strokes.

Any stroke can only belong to a single 2D layer. The selected layer is the active layer. Only one layer or group can
be active at a time. When you draw, the new strokes are added to the active layer. By default the view order of the
layers in the viewport is top to bottom.

Layers can be grouped using Layer Groups. A layer can only be in one group at a time. Layers can be moved into groups
using drag-and-drop. Groups can be color coded with a color tag.

Every layer correspond to a channel in the Dope Sheet editor (in Grease Pencil mode).
See [Dope Sheet](../../editors/dope_sheet/modes/grease_pencil.html) for more information.

Layers can also be used together with Modifiers to only affects part of your drawing.
See [Modifiers](../modifiers/introduction.html) for more information.

Layers can mask other layers by enabling Use Mask (mask icon) or using the checkbox in the Masks panel header. See
[Masks](#bpy-types-greasepenciltreenode-use-masks) for more information.

Layer Tree
:   Tree view of all layers and groups for the Grease Pencil object.

    Next to the layer name there are four icons buttons that control common properties of the layer:

    Use Mask (mask icon)
    :   Toggle the affect of [Masks](#bpy-types-greasepenciltreenode-use-masks) on the layer.

    Onion Skinning (onion skin icon)
    :   Toggle using the layer for [Onion Skinning](onion_skinning.html).

    Hide (eye icon)
    :   Toggle layer visibility in the viewport and in render.

    Lock (padlock icon)
    :   Toggle layer from being editable.

Add New Layer
:   Adds a new layer to the active object.

Add New Layer Group
:   Adds a new layer group to the active object.
    Note, layer groups cannot be added from the Dopesheet; they must be added from the Properties editor.

Remove Layer/Group
:   Removes the active layer or layer group.

Layer Specials
:   Operators for working with layers.

    Duplicate
    :   Makes an exact copy of the selected layer appending a number to differentiate its name.

    Duplicate Empty Keyframes
    :   Makes a copy of the selected layer but with empty keyframes. Useful to easily have empty keyframes preset to
        work on the cleanup or filling process.

    Show All
    :   Turns on the visibility of every layer in the list.

    Hide Others
    :   Turns off the visibility of every layer in the list except the active one.

    Lock All
    :   Locks editing of all the layers in the list.

    Unlock All
    :   Unlocks editing of all the layers in the list.

    Autolock Inactive Layer
    :   Automatically locks the editing of every layer in the list except the active one. This way you avoid making
        unwanted changes in other layers without the need to lock them every time.

    Ignore Material Locking
    :   Allow editing strokes even if they use locked materials.

    Merge Down `Shift`-`Ctrl`-`M`
    :   Combine the selected layer with the layer below, the new layer keeps the name of the lower layer.

    Merge Group
    :   Combine layers in the active layer group into a single layer.

    Merge All
    :   Combine all layers into the active layer.

    Mask with Layer Above/Below
    :   Adds a mask to the active layer with layer above or below.

    Copy Layer to Selected
    :   Copy the active layer to the selected Grease Pencil object.

    Copy All Layers to Selected
    :   Copy all layers to the selected Grease Pencil object.

Reorder Layer
:   Moves the active layer or layer group up/down in the tree.

Below the layers list there are additional settings:

Blend Mode
:   The layer blending operation to perform. See [Color Blend Modes](../../glossary/index.html#term-Color-Blend-Modes).

Opacity
:   Used to set the opacity of the layer.

Lights
:   When enabled, the layer is affected by lights.