In my script, I have
for loop over many cube objects (~1000) and the treatment is very slow. Looking more in details, I notice that in the same amount of loops:
if I use python operation or simple blender operation like
obj = bpy.data.objects[obj_name]
obj.select = True
it takes less than 0.08s (for all 1000 objects)
but as soon as I start using blender operators like:
bpy.ops.object.select_pattern() # or bpy.ops.object.duplicate() # or bpy.ops.object.location_clear() # or bpy.ops.object.transform_apply() # etc.
then, the performance drops down deeply with more than 6s for the same amount of objects.
And, a last information, if I reduce the amount of objects from 1000 to 50, the same set of operations with
bpy.ops is 0.03s - so extrapolating, it would be 0.6s for the 1000 objects and not 6s. It is as is with 1000 objects, we loose a factor 10 in speed in comparison than with 50 objects.
I tried reducing the complexity of my mesh changing the cubes in planes but it had no effect at whole on performance.
Is there something particular to know to improve these performance or a way to use the
bpy.ops methods with better performances? Obviously, I am missing something important probably.