This question already has an answer here:
I know that this has been asked before, but the answers that others have received did not help me much. When creating objects through Python, using bpy.ops.mesh.primitive_cube_add() there is an exponential slowdown when looping the creation of objects. My script that I am writing takes an image and creates a grid of cubes based on every pixel. It also assigns a material to each cube based on each pixel's color. When running it on a 32x32 image, it is very fast (about 1 second). When running it on a 100x100 image, the script gets slower and slower as it runs. I also have learned that using a low-level method to create my cubes I won't experience the slowdown. I changed my code to a low-level method, and the speeds are much faster, but I still experience the slowdown.
copy = ob.copy() copy.data = ob.data.copy() copy.data.materials.append(material) copy.location.x = x - 1 copy.location.y = y - 1 copy.location.z = 1 bpy.context.scene.objects.link(copy)
Here is my current code for creating cubes. My full addon can be accessed here: https://gist.github.com/MrSprite/ff7fda1ec4bf6850d357
Is there a faster/better way of doing this? Because I would really like to be able to create 100,000+ cubes without waiting hours.