2

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?

  • instead of 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 – Gorgious Feb 08 '22 at 19:55
  • Thanks @Gorgious, your comment that you've never had to flush got me thinking if it was the way I was calling the script... It works from the built-in text editor. Will post an answer with the details! – user1938312 Feb 08 '22 at 20:37

1 Answers1

4

Solved thanks to @glorious. I was calling the script from the blender python console with:

filename = 'script.py'
exec(compile(open(filename).read(), filename, 'exec'))

If I execute from the built-in text editor, all is good :-)