I have a long running script and would like to be able to see some form of progress indication - a simple print statement would do. From How to show to the user a progression in a script? and https://stackoverflow.com/questions/230751/how-can-i-flush-the-output-of-the-print-function-unbuffer-python-output , I have tried:
import sys
print(msg, flush=True)
sys.write(msg)
sys.stdout.flush()
My script is creating objects based on the contents of a CSV file:
import bpy
import csv
import sys
csvfile = open('c:/temp/input.csv')
inFile = csv.reader(csvfile, delimiter=',', quotechar='"')
# skip header
inFile.__next__()
i=0
for row in inFile:
if row[0] not in bpy.data.objects:
size = 0.0002
x = float(row[0])
y = float(row[1])
elev = float(row[2]) / 10
z = (elev / 2) * size
bpy.ops.mesh.primitive_cube_add(size=size, enter_editmode=False, align='WORLD', location=(x, y, z), scale=(1, 1, elev))
materialName = "ourMaterial"
obj = bpy.context.view_layer.objects.active
obj.active_material = bpy.data.materials[materialName]
msg = "%d: %f, %f, %f, %f" % (i, x, y, elev, z)
print(msg, flush=True)
sys.stdout.write(msg)
sys.stdout.flush()
The output does not show in the Blender System window (Window->Toggle System Console).
Is there something else I need to add to the script to pause execution for the output to flush?
time.sleep
you can use application timers to buffer between iterations. I've never had to use flush for printing things in the system console $\endgroup$