Reputation: 3168
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()
?
Upvotes: 9
Views: 14616
Reputation: 499
If you plan on creating a lot of text objects I would recommend using low level code instead of bpy.ops in order to increase the speed of code execution:
import bpy
myFontCurve = bpy.data.curves.new(type="FONT",name="myFontCurve")
myFontOb = bpy.data.objects.new("myFontOb",myFontCurve)
myFontOb.data.body = "my text"
bpy.context.scene.objects.link(myFontOb)
bpy.context.scene.update()
Upvotes: 11
Reputation: 747
bpy.ops.object.text_add()
ob=bpy.context.object
ob.data.body = "my text"
Upvotes: 15