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

assistant: The animation data inside an action is further organized into *Slots*. Each
action has a set of slots and different animation data for each of those slots.
An animated data-block then specifies both an action and a slot within that
action, and that determines which animation data the data-block is animated by.

[image reference removed]

Action selector and its accompanying slot selector in the properties of an
object, for seeing and selecting which action and slot animate the object.

The purpose of slots is to allow an action to store distinct animation data for
multiple data-blocks. For example, you may have an animation of a bouncing ball
that changes its color on each bounce, and that involves two data-blocks: the
object and its material. Slots allow you to put both the object’s animation and
the material’s animation in the same action by having a different slot for each.

[image reference removed]

Visualization of a ball and its material connected to different slots in an
action.

In this example there is one slot for an object and one slot for a material, but
you can have as many slots as you like for as many objects, materials, lights,
etc. as you like. If you’re baking down a simulation of 100 bouncing balls, you
could store that animation in single action with 100 slots.

[image reference removed]

Visualization of many balls all connected to different slots in an action.

Not all actions need to take advantage of slots: you are free to use 100
separate actions for all those bouncing balls if you prefer. Nevertheless, the
animation data in an action is always organized into slots, and therefore you
need at least one slot in an action in order to animate something.

Note that slots are not “for” any specific data-block: any data-block can use
any slot. For example, you can have two different characters use the same slot
in the same action, and they’ll both simply get animated by the same animation
data. Slots are just a way to organize distinct animation data within an action,
and don’t have any intrinsic attachment to anything in the scene.

### Slot Names and Associated Types

Each slot in an action has a name, and you are free to name them whatever you
like. By default, new slots are named after the last slot assigned to the
data-block they were created for, or after the data-block itself if it’s never
been assigned a slot before.

In addition to having a name, each slot also has an associated data-block type
that it is intended for (for example, “material”, “object”, etc.). This is set
automatically when a slot is first assigned to animate a data-block.

One of the places you can see a slot’s associated type is in the action editor’s
channel list, where it’s displayed as an icon next to the slot’s name.

[image reference removed]

Slots displayed in the [Action Editor’s](../editors/dope_sheet/modes/action.html)
channel list, with their associated type as an icon to the right of their name.

Within an action, a slot must have a unique combination of name + associated
type. For example, you can have two slots named “Cube” in an action as long as
one of them is for objects and the other is for materials, but not if they are
both for objects. When they are both for objects, their associated type is the
same, and thus they must have different names. In that case Blender will use the
familiar approach and name them “Cube” and “Cube.001”.