# Link a material animation with an armature animation

I am writing a custom exporter and need to determine which material animations go with specific armature animations. For example, my armature might have an action for throwing a punch, and the face material for the mesh attached to the armature might have an action for a concentrated expression (created via nodes). During the export, I need to be able to tell that these animations "go together." Is there a way to merge them into a single action in Blender? Or another way of associating the two together? Since there may be multiple such pairings I cannot rely on whatever the active action is for each.

• can you add the paired actions each to the same NLA strip? If you do that, then you could scan the NLA data for the pairs of related actions. Oct 21 at 22:17
• @MartyFouts I think that might work... I create a meta-strip that includes both of the actions. Then I would search through animation_data.nla_tracks for both the material and the armature to find ones with matching strip names. Right?
– SAMM
Oct 21 at 23:04
• yes that should work Oct 21 at 23:05

Here's a quick draft of Marty Fouts' proposed solution:

import bpy

arma = bpy.context.object

assert arma.type == 'ARMATURE' and arma.animation_data is not None \
and len(arma.children) > 0 and arma.children[0].type == 'MESH'

mesh = arma.children[0]

for track1 in arma.animation_data.nla_tracks:
if len(track1.strips) == 0:
continue
strip1 = track1.strips[0]
for slot in mesh.material_slots:
nodes = slot.material.node_tree
if nodes.animation_data is None:
continue
for track2 in nodes.animation_data.nla_tracks:
if len(track2.strips) == 0:
continue
strip2 = track2.strips[0]
if strip1.name == strip2.name:
assert strip1.type == 'META' and  strip2.type == 'META'
arma_anim_name = strip1.strips[0].name
mat_anim_name = strip2.strips[0].name
arma_act = bpy.data.actions[arma_anim_name]
mat_act = bpy.data.actions[mat_anim_name]
# export actions...


A bunch of ugly asserts that would be better dealt with gracefully, but it captures the idea.