# Exporting only one animation to gltf from multiple objects each with an action

I want to do an animated gltf file that shows how a set of molecules move. Using python, I created an object for each atom, 1558 atoms in total and then I added keyframes for updating the locations each frame. Then I exported to gltf and I can see the molecules moving alright in the online viewer. The problem is that there is an animation per each atom and I want only one animation in the file that includes all the atoms.

I tried putting all the actions in a single NLA strip but when I export the file I don't even see the strip in the viewer, not sure why (I do select the option for exporting NLA strips) and I still see the 1558 different animations. Any help would be appreciated.

Update If I create a few spheres and add keyframes manually, then everything is exported to a single animation as I want. When I compare this to the file generated with python, I see that the F curves created for the objects actions are grouped into an ActionGroup called 'object tranfroms' but that group is not generated when I insert the keyframes by scripting. I don't know if that grouping makes the GLTF have a single animation as I want.
How can I insert a keyframe programmatically that exactly replicates what happens when you manually press I over the object to insert it? I already tried adding an ActionGroup to the object but it is a read-only type and I think you can't add a F Curve to it.

• Did you try turning off the "Group by NLA Track" checkbox? When that box is turned off, all movements in the Blender project should be lumped together into a single glTF animation. – emackey Nov 24 '20 at 17:01
• I did with no luck. After many hours trial and error, I found that you have to group all the channels and then export without grouping by NLA Track – user2812681 Nov 24 '20 at 19:45

Not sure why but I got it to work by grouping the channels using this code:

for obj in bpy.context.selected_objects:
new_group=obj.animation_data.action.groups.new("ChGroup")
for fc in obj.animation_data.action.fcurves:
fc.group=new_group


And then exporting to gltf without selecting NLA Track:

bpy.ops.export_scene.gltf(export_format='GLB', filepath=filepath, export_nla_strips =False )


Now there is only one animation in the gltf (the color is different too but that's unrelated):

• I was wrong about the channels having to be in a group. What was working was exporting with the NLA strips option set to False. I guess that when I was exporting from Blender I was changing the other predeterminate values as well. – user2812681 Nov 25 '20 at 20:06