I'm trying to understand the blender tips you get when you hover and object. I think i am misunderstanding something, because I can't use the commands blender are giving me.

For example, I want to change the world background color to white with a blender script.

If i hover the setting I get a python command. I can also go to the scripting tab and see what python commands blender executes:

bpy.data.node_groups["Shader Nodetree"].nodes["Background"].inputs[0].default_value = (1, 0, 0, 1)

But if i copy that to a python file and execute it with blender it does not work:

KeyError: 'bpy_prop_collection[key]: key "Shader Nodetree" not found'

1 Answer 1


The command you want is: bpy.context.scene.world.node_tree.nodes["Background"].inputs["Color"].default_value

This will access the background color of the world in the current scene.

Your command doesn't work, because you're not in the right context. If you're in the scripting workspace and take a look at the bottom left window, you'll see that before bpy.data.node_groups["Shader Nodetree"].nodes["Background"].inputs[0].default_value = (0, 0, 0, 1) is bpy.context.space_data.context = 'WORLD'. In the wrong context it's entirely unclear which node tree you're trying to access. That being said, I don't know why the command in printed as it is, because even in the color picker it would rely on the context passed to the panel and not access data like this (because it wouldn't work either).

The Blender Python API docs are always helpful, as well as CTRL+SPACE in the Python console for possible options.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .