I want some selected font object to be converted to mesh
got this small loop but not working as expected
cn1 = 0
for obj in bpy.data.objects:
if (obj.select_get() is False and obj.type == 'FONT'):
bpy.ops.object.convert(target='MESH', keep_original=False)
print (' obj is selected ',obj.name ,' Converted to Mesh type =',obj.type )
cn1 +=1
You can append all font objects to a list, then call bpy.ops.object.convert and pass the list as override.
import bpy
def convert_font_mesh():
objects = bpy.context.view_layer.objects
to_convert = []
for obj in objects:
if obj.select_get() and obj.type == 'FONT':
to_convert.append(obj)
if to_convert:
active = objects.active
if active not in to_convert:
objects.active = to_convert[0]
ctx = {'selected_editable_objects': to_convert}
bpy.ops.object.convert(ctx, target='MESH', keep_original=False)
objects.active = active
print("Converted %s fonts." % len(to_convert))
if __name__ == "__main__":
convert_font_mesh()
The operator expects context.selected_editable_objects which is already a list. Adding all selected fonts to a list and running the operator once is faster than running it for every object.