Skip to content

Instantly share code, notes, and snippets.

@GGLinnk
Last active April 28, 2022 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GGLinnk/744ea8f201e35d612ad907468d7de208 to your computer and use it in GitHub Desktop.
Save GGLinnk/744ea8f201e35d612ad907468d7de208 to your computer and use it in GitHub Desktop.
Blender Python API: Gets collections by creating them or getting them by name.
import bpy
def get_collection(collection_name: str) -> bpy.types.Collection:
return bpy.data.collections.get(collection_name) or bpy.data.collections.new(collection_name)
def get_collections(collection_names: list) -> list:
return [get_collection(collection_name) for collection_name in collection_names]
if __name__ == __main__:
get_collection("TEST_COLLECTION")
get_collections(["TEST_COLLECTION", "COL1", "COL2"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment