User:Sybren/SfA/SceneBuilding

= Scripting for Artists: Scene Building =


 * About constructing a scene with Python.
 * JSON file with scene description.
 * Link assets from blend files.
 * Put them into the scene in the right collection.

Linking assets from Python
Start with the linking, because that's the biggest unknown. We have managed collections before (https://cloud.blender.org/p/scripting-for-artists/5e7c941c5afb8fa58fad6718). Parsing a JSON file is also an unknown for now, but only once we know how we link things to a blend file will we know what we want to put into that JSON file.

Start with docs.

Simple script to explore
Note that in the outliner, Libraries, the blend file is listed. Also in `bpy.data.libraries`.

Filter collections by name
Now in the outliner you can see the linked collections. Saving & reloading the file still removes them, because they are not yet used.

Instancing into the scene
First do this by hand, to explore what happens.

An instance is just a carefully crafted Empty.
 * Create the Empty with the name of the collection.
 * Set it to instance that collection (`.instance_type = "COLLECTION"`, `.instance_collection = coll`)
 * Link it to the desired scene collection.

Parsing JSON file

 * JSON is not the most human-friendly, but quite simple, and support is built into Python.
 * Meaning of `{}` and `[]` pretty much the same as in Python (dict vs. list).