Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MichaelGatesDev/5c3b509215d0fdafa6c2e067f4774a50 to your computer and use it in GitHub Desktop.
Save MichaelGatesDev/5c3b509215d0fdafa6c2e067f4774a50 to your computer and use it in GitHub Desktop.
This will take each action that exists on the armature and export it with the armature with the file named as the action name. For use with Blender 2.91.
import bpy
import os
filepath = bpy.data.filepath
directory = os.path.dirname(filepath)
all_action_names = [a.name for a in bpy.data.actions]
def remove_all_actions_except(ignored):
for a in bpy.data.actions:
if a.name == ignored:
continue
bpy.data.actions.remove(a)
for name in all_action_names:
remove_all_actions_except(name)
print("Exporting rig with single action: " + name)
fbx_file_name = os.path.join( directory , name + ".fbx")
bpy.ops.export_scene.fbx(
filepath = fbx_file_name,
check_existing = False,
object_types={'ARMATURE'},
axis_forward = "Z",
add_leaf_bones = False,
bake_anim_use_nla_strips = False,
bake_anim_force_startend_keying = False,
embed_textures=False,
)
bpy.ops.wm.revert_mainfile()
@MichaelGatesDev
Copy link
Author

I would love if there were a way to avoid calling revert_mainfile as it is the chokepoint of this script, especially on larger files.. I tested on ~120MB files and it took about an hour to export ~350 actions this way. Unfortunately calling 'undo' doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment