So far I have seen this and this both which did not work for me. Currently I have:
import bpy
bpy.data.scenes['Scene'].render.engine = "CYCLES"
bpy.ops.mesh.primitive_cube_add(radius=1, view_align=False, enter_editmode=False, location=(1.00003, 0.176902, 0.72441),
layers=(True, False, False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False))
bpy.ops.object.material_slot_add()
bpy.ops.material.new()
mat_name = 'Material.001'
bpy.data.materials[mat_name].node_tree.nodes.new("ShaderNodeEmission")
bpy.data.materials[mat_name].node_tree.nodes["Emission"].inputs["Color"].default_value = (1, 0, 0.07, 1)
mat = bpy.data.materials.get(mat_name)
ob = bpy.context.active_object
ob.data.materials[0] = mat
When I perform this process in blender the hover text for use nodes in the material->surface section the code is: bpy.ops.cycles.use_shading_nodes() and I get: RuntimeError: Operator bpy.ops.cycles.use_shading_nodes.poll() failed, context is incorrect so I'm not sure if I can/have to perform this action or there is a prerequisite to doing it?
I tried starting blender with --debug-wm but this didn't give me more information of how to perform this action in a script.
Is there a better way to show what blender is doing than --debug-wm? Because I can do what I want in blender itself just not in a script.
I also read a lot of api documentations and the tips for blender scripting, but this didn't really help me.