Skip to main content
broader title (blender version doesn't really matter)
Link
brockmann
  • 12.8k
  • 4
  • 51
  • 94

How can I add a collection using Python in 2.83?

Source Link
Richard
  • 143
  • 1
  • 4

How can I add a collection using Python in 2.83?

I'm new to Blender. Tutorial information as recent as January this year appears to be out of date and I can't figure out how to create a new collection and add an object to it. The most recent relevant question I could find suggests this:

bus_collection = ops.collection.new(name="BusRoutes")
context.scene.collection.children.link(bus_collection)

and apparently at least needs to be changed to this:

bus_collection = ops.collection.create(name="BusRoutes")
etc.

which throws the error:

TypeError: CollectionChildren.link(): error with argument 1, "child" -  Function.child expected a Collection type, not set

The API entry for Collection operators is beyond sparse, and I'm not even sure what Add the object to an object collection that contains the active object even means.

May I ask someone to give me a minimal Blender 2.83 Python example of how to create a named collection and add an object to it? Many thanks.