Skip to content

Instantly share code, notes, and snippets.

@Suaz
Created December 30, 2024 21:47
Show Gist options
  • Save Suaz/29b3cc414d8880b3f5d2804c7b4640c9 to your computer and use it in GitHub Desktop.
Save Suaz/29b3cc414d8880b3f5d2804c7b4640c9 to your computer and use it in GitHub Desktop.
Export meshes from blender
import bpy
import os
# Set the directory where you want to save the exported files
export_dir = "/Users/csuaznabar/Documents/Blender/assets"
# 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
bpy.ops.export_scene.fbx(filepath=file_path, use_selection=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