Setting World to active

How can I set the loaded world to be the active one?

I linked the World from other file using:

hdri_path = “//hdri.blend
with bpy.data.libraries.load(hdri_path, link=link) as (data_from, data_to):
data_to.worlds = data_from.worlds

All that is missing now is loading that world into the active world slot.
That world is there in drop down menu but it is not assigned.
For the love of me I can’t find anything in blender API documentation which function does that.

Thanks in advance!

I know this is kinda old, but just in case anyone else has this problem, here’s the answer:

After you load the world in, you can get a reference to it like this:

my_world = data_to.worlds[0]

As long as you are outside the load function when you call this, it should give you the reference to the actual data block, rather than just the name.
Then, you can set the active world with:

bpy.context.scene.world = my_world
1 Like