Hi guys,
I have created my first Blender Python script the last couple of days which went far more smoothly than expected considering that I am no coder. The only problem I ran into is performance. (1 second per iteration) As soon as I call Blender functions, loops become very slow. In particular I am instancing two very simple groups in the 3D viewport and distribute them in a grid. One of the groups is scaled. (I basically create a custom 2D amplitude grid.)
Here is the part of the script that slows it down (This function is called by the for loop.):
def createInstance(scalefactor, linewidth, loc):
bpy.ops.object.group_instance_add(group='box', location=loc, layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
bpy.ops.transform.resize(value=(scalefactor, scalefactor, scalefactor))
bpy.ops.object.group_instance_add(group='box_inner', location=loc, layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
bpy.ops.transform.resize(value=(scalefactor, scalefactor, scalefactor))
linewidth = round(0.5 + (linewidth*linewidth)*0.5, 1)
bpy.ops.transform.resize(value=(linewidth, 1, linewidth))
return
If I comment the “bpy.ops.object.group_instance_add” calls, it becomes blazingly fast. Interestingly the round() function causes it to significantly slow down even more by an estimated factor of 2-3. That’s the case even tho the rounding function itself is not slow as long as the group_instance_add stuff is deactivated.
Help would be greatly appreciated!
Sebastian