I have been trying to use the bpy.ops.object.convert(target='MESH') to convert my font objects into mesh and curve objects. I have observed other people reporting problems doing this conversion. In the enclosed figure, the specific error that is reported is reported starting on line 22. When I do this operation manually, the conversion works fine. it is only when I try to write the python code that this problem happens. Any suggestions would be much appreciated. Thanks.
1 Answer
$\begingroup$
$\endgroup$
2
I think the problem is that select_all
only sets the Font Object
object as, well, select
'd, not active
. The bpy.ops.object.convert
operator seems to expect that it is both active
and select
'd. (Also, side note; I avoid using select_all
below, so that I don't select extra objects unintentionally.)
Making sure it is also the active
object seems to work (tested in 2.83; I live in the past!):
import bpy
font_curve = bpy.data.curves.new(type="FONT", name="Font curve")
font_curve.body = "testing"
font_obj = bpy.data.objects.new(name="Font Object", object_data=font_curve)
bpy.context.scene.collection.objects.link(font_obj)
bpy.context.view_layer.objects.active = bpy.data.objects['Font Object'] # Need a reference to an `object`, not `TextCurve`, for this to work
bpy.context.object.select_set(True)
bpy.ops.object.convert(target='MESH')
-
$\begingroup$ Thank you NeverConvex for your insight in solving my problem. I have tested for Blender 3.4.1 with both MESH and CURVE options for convert and works great! Best Regards! $\endgroup$– SteveKCommented Dec 26, 2022 at 9:57
-
$\begingroup$ Glad it helped -- since it seems to have fixed the problem, would be helpful if you marked the answer as
Accepted
$\endgroup$ Commented Dec 26, 2022 at 15:55