2
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – Mutant Bob
    Commented Jun 12, 2016 at 21:26

2 Answers 2

2
$\begingroup$
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
$\endgroup$
2
  • $\begingroup$ I think last example is almost doing all what I needed $\endgroup$
    – Ricky
    Commented Jun 13, 2016 at 19:29
  • 1
    $\begingroup$ @Ricky Then you should accept it. $\endgroup$
    – p2or
    Commented Jul 12, 2016 at 22:58
0
$\begingroup$

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 = nt.nodes.new('ShaderNodeOutputMaterial')
    out.location = (0,0)

    mix = nt.nodes.new('ShaderNodeMixShader')
    mix.location = (-200,0)
    mix.inputs[0].default_value = 0.15

    nt.links.new(out.inputs[0], mix.outputs[0])
#...
    nt.links.new(mix2.inputs[0], speckle1.outputs[1])
    nt.links.new(mix2.inputs[1], speckle2.outputs[0])
    nt.links.new(mix2.inputs[2], speckle1.outputs[0])

    return mat



def mission1():
    mat = random_pebble_material()
    obj = bpy.context.active_object
    obj.data.materials[0] = mat
$\endgroup$

You must log in to answer this question.

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