blender script: how to write to text object

groovehunter picture groovehunter · Jun 30, 2013 · Viewed 9.6k times · Source

I use blender 2.6 and add a text object with

bpy.ops.object.text_add(location=(x,y,z))

and just want to set the text and cannot figure that out. I found in the python console that I can

bpy.data.texts['Text.001'].write("my text")

but (also generally) am confused how to reference the last created object to perform something on it. In tutorials there is the primitive_MESHTYPE_add shortcuts which return not the object created. Can you tell me how to do Text.new()?

Answer

retroj picture retroj · Mar 6, 2014
bpy.ops.object.text_add()
ob=bpy.context.object
ob.data.body = "my text"