I'm trying to use Python to create a sun lamp (in Cycles mode) and then change it's strength. I began by performing the operations manually and then copying the Python code that was produced in the top output area. When I then run the script, the sun lamp is created, but I get an error before the strength can be set. Here's the code:
import bpy
bpy.context.scene.render.engine = 'CYCLES'
bpy.ops.object.lamp_add(type='SUN', view_align=False, location=(0, 0, 0))
bpy.context.space_data.context = 'DATA'
bpy.data.node_groups["Shader Nodetree"].nodes["Emission"].inputs[1].default_value = 2
Which produces this error:
File "/Text", line 5, in <module>
AttributeError: 'SpaceTextEditor' object has no attribute 'context'
It seems as though the problem is that I'm not properly telling Blender what object I want to change?
The answer (thanks to poor):
import bpy
bpy.context.scene.render.engine = 'CYCLES'
bpy.ops.object.lamp_add(type='SUN', view_align=False, location=(0, 0, 0))
bpy.context.object.data.node_tree.nodes['Emission'].inputs['Strength'].default_value=3