Created
December 31, 2024 00:56
-
-
Save Suaz/38fcdb67e8b10cac5ef69aa2d2bdda63 to your computer and use it in GitHub Desktop.
Export bash for Blender
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 | |
import os | |
# Set the directory where you want to save the exported files | |
export_dir = "C:/path/to/export/directory" | |
# Ensure the directory exists | |
if not os.path.exists(export_dir): | |
os.makedirs(export_dir) | |
# Get all objects in the scene | |
objects = bpy.context.scene.objects | |
# Deselect all objects | |
bpy.ops.object.select_all(action='DESELECT') | |
# Loop through each object and export it as an individual file | |
for obj in objects: | |
if obj.type == 'MESH': | |
# Select the object | |
obj.select_set(True) | |
# Make the object active | |
bpy.context.view_layer.objects.active = obj | |
# Construct the file path | |
file_path = os.path.join(export_dir, f"{obj.name}.fbx") | |
# Export the object with materials | |
bpy.ops.export_scene.fbx(filepath=file_path, use_selection=True, bake_space_transform=False, | |
object_types={'MESH'}, use_mesh_modifiers=True, | |
mesh_smooth_type='FACE', add_leaf_bones=False, | |
primary_bone_axis='Y', secondary_bone_axis='X', | |
use_metadata=True) | |
# Deselect the object | |
obj.select_set(False) | |
print("Export completed!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment