I'm new to scripting in Blender, but after extensive googling and searching through the API, I've created the following script to create an empty scene (my default scene has no cube, light or camera in it), add a Text object, set some various parameters, and then convert it to a mesh. However, when trying to convert to a mesh, I get:
RuntimeError: Operator bpy.ops.object.convert.poll() failed, context is incorrect
The following is my script:
import bpy font_loc = #set to font location bpy.ops.wm.read_homefile() #load default (empty) scene bpy.ops.object.text_add() #create the text object mytext = bpy.data.objects["Text"] mytext.data.body = "A" #set some stuff up mytext.data.align_x = "CENTER" mytext.data.align_y = "BOTTOM" mytext.data.extrude = 0.1 fnt = bpy.data.fonts.load(font_loc) #font loading works mytext.data.font = fnt bpy.context.scene.objects.active = mytext #make sure my Text object is correctly selected mytext.select = True bpy.ops.object.convert(target="MESH") #<------ context is incorrect?
On that last line is when I get the error, but if I type that exact same line into the in-editor console after the script exits, it converts the Text object to a Mesh object perfectly fine. What's going on? Is there some other way to convert the Text object that I can't find?