1
$\begingroup$

I am trying to set up a sky in my script using bpy.context.scene.world.use_sky_paper = True which results in the following error:

AttributeError: 'NoneType' object has no attribute 'use_sky_paper'

Why does bpy.context.scene.world return None? Is there some setup required for the world?

I encountered a similar problem, when trying to see which area is active via bpy.context.area.type where area is None.

Update: bpy.context.area is always None when running script headless.

$\endgroup$
  • $\begingroup$ Your assignments working as expected for Blender 2.78c... Also context.area.type is never none. Cycles or Internal? What blender version? Are you trying to execute that commands headless (without UI)? $\endgroup$ – brockmann Aug 29 '17 at 8:54
  • $\begingroup$ I am using blender 2.78 with internal render. I am not scripting inside blender but using an external python script executed with blender --background --python <name_of_script>. Executing print(bpy.context.area) prints None to the console. $\endgroup$ – McLawrence Aug 29 '17 at 9:05
  • $\begingroup$ Since you are running these commands headless and bpy.context.area returns the active area of the UI, it's totally obvious why the property is none. Also I have no problems printing World.use_sky_paper to the command line. Does this example helps? $\endgroup$ – brockmann Aug 29 '17 at 9:22
  • $\begingroup$ ok. So that part of my question is answered. The mode of the object is already object mode. The error persists when inserting bpy.ops.object.mode_set(mode='OBJECT') as suggested by the example. $\endgroup$ – McLawrence Aug 29 '17 at 10:10
1
$\begingroup$

If not set scene.world is None. Simply set it, for example to a world named "World" with scene.world = bpy.data.worlds.get("World") , or create a new one.

import bpy

scene = bpy.context.scene

if scene.world is None:
    # create a new world
    new_world = bpy.data.worlds.new("New World")
    new_world.use_sky_paper = True
    scene.world = new_world
$\endgroup$
  • $\begingroup$ I am at the moment on another device: On my MacBook, it seems scene.world is already defined from the beginning. So I can check your solution only tomorrow. Any idea why that can depend on the PC, if blender version and script are the same? $\endgroup$ – McLawrence Aug 29 '17 at 16:34
  • 1
    $\begingroup$ My guess would be to check startup.blend, you may have inadvertently removed world from scene. $\endgroup$ – batFINGER Aug 29 '17 at 16:44
  • $\begingroup$ Solution works. Problem was indeed with startup.blender $\endgroup$ – McLawrence Aug 29 '17 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.