# How can I edit text object properties with a script?

I have got some files with a lot of text objects for descriptions. Now I need to modify all these text objects.

Example:

Modify the curve resolution-U, but also modify the font bevel extrude. I can modify the extrude using this. Also if possible change the text color as I might need to add or replace existing material. All this using Cycles.

I can modify some parameters:

for ob in bpy.data.objects:

print ('ob =', ob.name, ' type =', ob.type)
if ob.type == "FONT":
qtyTEXT+=1

tcu = ob.data
print ( 'font name =',tcu.name )

#  Curve attributes
tcu.extrude = 0.2     # in BU
tcu.bevel_depth = 0.1    # in BU
tcu.bevel_resolution = 0


But this does not allow to change the curve text parameters like resolution!

Also, would be nice to be able to add a new cycles material for each of the text object.

• Almost any UI element in blender will pop up an info box if you leave your mouse over it long enough. Whatever this "resolution" you are talking about should have a pop-up box. I could not find anything called "resolution" in my quick scan of the UI, so you might have to post a screenshot to help me find it. – Mutant Bob Jun 12 '16 at 21:26

import bpy

# Set render engine to cycles
bpy.context.scene.render.engine = 'CYCLES'

textObjs = [ o for o in bpy.data.objects if o.type == 'FONT' ]
print( "No of text objs: %s" % len( textObjs ) )

for o in textObjs:
print( o.name )

# Set text properties
o.data.extrude             = 0.2
o.data.bevel_depth         = 0.1
o.data.bevel_resolution    = 0.1
o.data.resolution_u        = 12
o.data.render_resolution_u = 12

# Create a new material based on the object's name
o.active_material = bpy.data.materials.new(o.name + '.mat')
o.active_material.use_nodes = True

• I think last example is almost doing all what I needed – Ricky Jun 13 '16 at 19:29
• @Ricky Then you should accept it. – p2or Jul 12 '16 at 22:58

When it comes to creating cycles materials and assigning them to objects, take a look at http://web.purplefrog.com/~thoth/blender/python-cookbook/random-pebble-material.html which has code like

def random_pebble_material():

time_span=0.2
mat = bpy.data.materials.new("pebble")

mat.use_nodes = True

mat.node_tree.nodes.clear()

nt = mat.node_tree

out.location = (0,0)

mix.location = (-200,0)
mix.inputs[0].default_value = 0.15

#...