Skip to content

Instantly share code, notes, and snippets.

@robert-wallis
Created March 4, 2024 22:28
Show Gist options
  • Save robert-wallis/cd0d547f36121d9e151d9eb6cab0b736 to your computer and use it in GitHub Desktop.
Save robert-wallis/cd0d547f36121d9e151d9eb6cab0b736 to your computer and use it in GitHub Desktop.
A Blender 4.0 script to export collections into the ../items folder as png images.
# Renders each collection with Environment to the ./items/ folder
import bpy
import os
base_dir = os.path.dirname(bpy.data.filepath)
items_dir = os.path.join(base_dir, '../', 'items')
if not items_dir:
raise Exception(f"Looking for {items_dir} but it was not found.")
collections = bpy.context.layer_collection.children
# turn off all collections except Environment
for collection in collections:
if collection.name != 'Environment':
collection.exclude = True
for collection in collections:
if collection.name == 'Environment':
continue
# turn the collection on
collection.exclude = False
# figure out the filename for the render
filename = collection.name
filename = filename.lower().replace(' ', '-')
render_path = os.path.realpath(os.path.join(items_dir, filename))
print(f"Rendering {render_path}")
# render the item png
bpy.context.scene.render.filepath = render_path
bpy.ops.render.render(write_still=True)
# cleanup
collection.exclude = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment