Hi,
I’m trying to use python to automate the creation of scenes from collections by keeping the same name and settings, but I keep on getting errors…
Can someone please help me to figure it out?
Here is the script:
import bpy
def create_new_scene_for_each_collection_with_empty_type():
# Get all of the collections in the current scene.
collections = bpy.context.scene.collection.children
# Iterate over the collections and create a new scene for each collection.
for collection in collections:
# Create a new scene with the EMPTY type.
scene = bpy.ops.scene.new(type='EMPTY')
# Set the name of the new scene to be the same as the collection name.
# Fixed the error by checking if the collection is a dictionary object before accessing the `name` attribute.
if isinstance(collection, bpy.types.Collection):
scene.name = collection.name
else:
print("The collection does not have a name attribute.")
# Link the collection to the new scene.
scene.collection.children.link(collection)
# Set the active scene to the new scene.
bpy.context.window.scene = scene
# Create a new scene for each collection with the EMPTY type.
create_new_scene_for_each_collection_with_empty_type()
I only managed to get it work, but it’s not copying the render settings, with this script
import bpy
def create_new_scene_for_each_collection():
# Get all of the collections in the current scene.
collections = bpy.context.scene.collection.children
# Iterate over the collections and create a new scene for each collection.
for collection in collections:
# Create a new scene.
scene = bpy.data.scenes.new(collection.name)
# Link the collection to the new scene.
scene.collection.children.link(collection)
# Set the active scene to the new scene.
bpy.context.window.scene = scene
# Create a new scene for each collection and name it the same as the collection.
create_new_scene_for_each_collection()
Thank you!!