1
$\begingroup$

I'm trying to create a glowing object with a script. This is the code I have so far. It runs but the sphere doesn't light up. How can I fix this?

import bpy

# turn on bloom
bpy.context.scene.render.engine = 'BLENDER_EEVEE'
bpy.context.scene.eevee.use_bloom = True

# add material
mat_name = 'EmiMat'
bpy.ops.material.new()
bpy.data.materials[-1].name = mat_name
bpy.data.materials[mat_name].node_tree.nodes.clear()
bpy.data.materials[mat_name].node_tree.nodes.new("ShaderNodeEmission")
bpy.data.materials[mat_name].node_tree.nodes["Emission"].inputs["Color"].default_value = (0.151736, 0.0997155, 1, 1)
bpy.data.materials[mat_name].node_tree.nodes["Emission"].inputs["Strength"].default_value = 5.

# add sphere
bpy.ops.mesh.primitive_uv_sphere_add(location=(0,0,0))
bpy.ops.object.material_slot_add()
mat = bpy.data.materials.get(mat_name)
ob = bpy.context.active_object
ob.data.materials[0] = mat
```
$\endgroup$
1
  • 1
    $\begingroup$ Have a look at the material. Do you have a material output? $\endgroup$
    – Jackdaw
    Commented Aug 15, 2019 at 16:34

1 Answer 1

2
$\begingroup$

Thanks, @Jackdaw. That was the problem. Pardon for such a noob question. Today is my first day working with Blender.

Here is the working code:

import bpy

# turn on bloom
bpy.context.scene.render.engine = 'BLENDER_EEVEE'
bpy.context.scene.eevee.use_bloom = True

# add material
mat_name = 'EmiMat'
bpy.ops.material.new()
bpy.data.materials[-1].name = mat_name
bpy.data.materials[mat_name].node_tree.nodes.clear()
bpy.data.materials[mat_name].node_tree.nodes.new("ShaderNodeEmission")
bpy.data.materials[mat_name].node_tree.nodes["Emission"].inputs["Color"].default_value = (0.151736, 0.0997155, 1, 1)
bpy.data.materials[mat_name].node_tree.nodes["Emission"].inputs["Strength"].default_value = 5.
bpy.data.materials[mat_name].node_tree.nodes.new("ShaderNodeOutputMaterial")
links = bpy.data.materials[mat_name].node_tree.links
links.new(
    bpy.data.materials[mat_name].node_tree.nodes["Emission"].outputs[0], 
    bpy.data.materials[mat_name].node_tree.nodes["Material Output"].inputs[0])

# add sphere
bpy.ops.mesh.primitive_uv_sphere_add(location=(0,0,0))
bpy.ops.object.material_slot_add()
mat = bpy.data.materials.get(mat_name)
ob = bpy.context.active_object
ob.data.materials[0] = mat
$\endgroup$

You must log in to answer this question.

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