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()
?
bpy.ops.object.text_add()
ob=bpy.context.object
ob.data.body = "my text"
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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.