Last active
June 6, 2024 23:13
-
-
Save CakeLancelot/d2ebb8bcf339158c4e9f01e67fb7b77b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import bpy | |
| from bpy_extras.io_utils import ExportHelper | |
| from bpy.types import Operator | |
| from bpy.props import StringProperty | |
| class SaveAsOperator(Operator, ExportHelper): | |
| """Open a file browser to specify a file to save""" | |
| bl_idname = "wm.save_as_file" | |
| bl_label = "Export FBX (sep. animations)" | |
| filename_ext = ".fbx" | |
| def execute(self, context): | |
| # Get the list of all actions | |
| actions = bpy.data.actions | |
| # Get the active object | |
| obj = bpy.context.active_object | |
| # Export mesh with no animations | |
| bpy.ops.better_export.fbx(filepath=self.filepath, my_fbx_version='FBX200900', use_animation=False, use_edge_crease=False) | |
| # Iterate through all actions | |
| for i, action in enumerate(actions): | |
| # Set the action to the active object | |
| obj.animation_data.action = action | |
| index = self.filepath.find('.fbx') | |
| output_line = self.filepath[:index] + f'@{action.name}' + self.filepath[index:] | |
| # Export singular animation | |
| bpy.ops.better_export.fbx(filepath=output_line, my_fbx_version='FBX200900', use_edge_crease=False) | |
| return {'FINISHED'} | |
| # Register the operator | |
| def register(): | |
| bpy.utils.register_class(SaveAsOperator) | |
| def unregister(): | |
| bpy.utils.unregister_class(SaveAsOperator) | |
| if __name__ == "__main__": | |
| register() | |
| # Launch the file browser immediately | |
| bpy.ops.wm.save_as_file('INVOKE_DEFAULT') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment