0

I want to create multiple primitives such as spheres via python, but my current approach is too slow:

import bpy
import time

t0 = time.time()
for i in range(400):
    bpy.ops.mesh.primitive_ico_sphere_add(radius=0.5, location=[i * 10, 0, 0])

t1 = time.time()
dt = t1 - t0
print(dt)

This code takes about 5 seconds, which is just too slow (why?). Is there a way to make it run faster? I suspect creating the mesh every single iteration might be too slow and there is probably a better way to create multiples copies with the same shared mesh, but only different positions, which might be faster.

Mei Zhang
  • 125
  • 4
  • Create Object instance in Blender is slow since there is a whole object class need to be instantiate. Did you mean Duplicate Linked? bpy.ops.object.duplicate_move_linked – HikariTW Mar 31 '20 at 06:17
  • 1
    Also relative one: https://blender.stackexchange.com/questions/7358/python-performance-with-blender-operators – HikariTW Mar 31 '20 at 06:37
  • For any of the linked dupes pre 2.8 may use scene.objects.link(ob) change to collection.objects.link(ob) for 2.8 – batFINGER Mar 31 '20 at 10:45

0 Answers0