I like to create a text:

How do I set the Text value?(Not the naming in the object-tree)

import bpy
def create():
    bpy.ops.object.text_add(location=(0, 0, 0), rotation=(45,0,0))
    text_obj = bpy.context.object
    text_obj.name = "Text" #Objectname
    text_obj.rotation_euler.x = radians(90) # Rotate text by 90 degrees along X axis
    text_obj.data.extrude     = 0.05        # Add depth to the text
    text_obj.data.bevel_depth = 0.01        # Add a nice bevel effect to smooth the text's edges
    text_obj.data.body        = "Digital"        # Set the text to be the current row's date

    #'Emission material'
    glow_material = D.materials["font"]
    #mat = makeMaterial("font", (1,1,1), 1.8)
    text_obj.active_material = glow_material

My goal is to set text values automated by just setting the name of the text. Then animating the text e.g. moving into camera view. Therefore I am also looking for location, rotation and how to change the extrude value of a text_object. Anyone can help me and give me a short example on this? The shown code seems to be using the right function, but the result is not (Material not assigned and none of the attributes are set like "Digital" as body. Anyone can run the code and help me understand how Blender Python scripting actually works?

I am quite new to bpy library ;)

:) Thanks! Current Example

  • $\begingroup$ HI. Please only ask one question at a time. You are welcome to ask as many questions as you need to as separate posts. $\endgroup$ Oct 28 '17 at 15:02
  • $\begingroup$ ok sure ;) print("test") $\endgroup$
    – Lukas Ott
    Oct 28 '17 at 15:39
  • $\begingroup$ I don't understand. The code your posted does most(if not all) of what your asking. Do you not know what each part of the code does? $\endgroup$
    – cmomoney
    Oct 28 '17 at 16:42
  • $\begingroup$ The text object does not change (Body still shows "Text" I like e.g. "Digital" or whatever I will set in variable...do I need to run a update function? $\endgroup$
    – Lukas Ott
    Oct 28 '17 at 16:48
  • $\begingroup$ by chance have you forgotten to call create()? It's just a method definition and will do nada unless called elsewhere in script. $\endgroup$
    – batFINGER
    Oct 29 '17 at 17:45

This is how I solved it:

import bpy
import bmesh

def create():
    scn = bpy.context.scene
    scn.render.engine = 'CYCLES'
    scn.world.use_nodes = True
    bpyscene = bpy.context.scene

# Create an empty mesh and the object.
    mesh = bpy.data.meshes.new('Basic_Sphere')
    basic_sphere = bpy.data.objects.new("Basic_Sphere", mesh)

# Add the object into the scene.
    bpyscene.objects.active = basic_sphere
    basic_sphere.select = True

# Construct the bmesh cube and assign it to the blender mesh.
    bm = bmesh.new()
    bmesh.ops.create_uvsphere(bm, u_segments=32, v_segments=16, diameter=1)

# add subsurf mod and smooth
# add material to the UV Sphere
    ob = bpy.context.active_object
    ob.select = True
#scene.objects.active = ob

# Get material
    g_mat = bpy.data.materials.get("green_glow")
    if g_mat is None:
    # create material
    g_mat = bpy.data.materials.get("green_glow")
# Assign it to object
    if ob.data.materials:
    # assign to 1st material slot
        ob.data.materials[0] = g_mat        
    # no slots
    print ("Green Material assigned")

# move UV Sphere
    bpy.ops.object.move_to_layer(layers=(False, False, False, False, False, False, False, False, False, False, True, False, False, False, False, False, False, False, False, False))

# Text
bpy.ops.object.text_add(view_align=False, enter_editmode=False, location=(0, 0, 0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
bpy.ops.transform.rotate(value=1.5708, axis=(1, 0, 0), constraint_axis=(True, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
bpy.context.object.data.extrude = 0.02
# Delete default "Text"
# Set new word
chars = "Digital"
for char in chars:
# add material to the Text
ob.select = True
ob = bpy.context.active_object
#scene.objects.active = ob

# Get material
mat = bpy.data.materials.get("white_glow")
if mat is None:
    # create material
mat = bpy.data.materials.get("white_glow")
# Assign it to object
if ob.data.materials:
    # assign to 1st material slot
    ob.data.materials[0] = mat
    # no slots
print ("Green Material assigned")
# text to mesh
# Particle system
bpy.data.particles["ParticleSettings"].effector_weights.gravity = 0
bpy.data.particles["ParticleSettings"].render_type = 'OBJECT'
bpy.data.particles["ParticleSettings"].dupli_object = 

def set_background():
# darken the background   
.inputs['Color'].default_value = (0, 0, 0, 1)

print("Set background color")

def create_materials(mat_name):
mat = bpy.data.materials.new(name=mat_name)
# get the material
mat = bpy.data.materials[mat_name]
mat.use_nodes = True
# get the nodes
nodes = mat.node_tree.nodes

# clear all nodes to start clean
for node in nodes:

# create emission node
node_emission = nodes.new(type='ShaderNodeEmission')
if (mat_name == "white_glow"):
    node_emission.inputs[0].default_value = (1,1,1,1)  # white RGBA
    node_emission.inputs[0].default_value = (0,1,0,1)  # white RGBA
node_emission.inputs[1].default_value = 2.0 # strength
node_emission.location = 0,0

# create output node
node_output = nodes.new(type='ShaderNodeOutputMaterial')   
node_output.location = 400,0

# link nodes
links = mat.node_tree.links
link = links.new(node_emission.outputs[0], node_output.inputs[0])

# remove links

# Animate Particle System
#def animate():

# Move / Animate Sphere

if __name__ == "__main__":

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.