# How to show to the user a progression in a script?

I'm making an python script which create a lot of object and this could take a lot of time. My question is how to show to the user of my script, the "progression" of the script? For now I print an progress bar in the system console.

But you have to open the system console befor and (apparently) the system console only work with Windows.

Is there an other way to show the progression of my script with python like control the mouse percentage icon (the little icon that replace the mouse while baking) or another idea?

• – iKlsR Oct 7 '13 at 12:56

Currently the only (simple) way to do this is to show the progress with the mouse cursor.

import bpy
wm = bpy.context.window_manager

# progress from [0 - 1000]
tot = 1000
wm.progress_begin(0, tot)
for i in range(tot):
wm.progress_update(i)
wm.progress_end()

• Thank's for your answer. You say "the only (simple) way". Does this means that you know other (hard) ways to do it? And of course other than those indicated in other answer? – lucblender Oct 11 '13 at 13:53
• @lucblender with python a lot of hacks are possible, like calling into operating system specific progress bars which display in the window list, or writing a modal operator that draws text in the 3d view with a timer, its possible but way overkill in almost all cases. – ideasman42 Mar 12 '14 at 20:04
• Progress of script can also be printed and updated with sys module to the console:

import sys
from time import sleep

sys.stdout.write("Some job description: ")
sys.stdout.flush()
some_list = [0] * 100
for idx, item in enumerate(some_list):
msg = "item %i of %i" % (idx, len(some_list)-1)
sys.stdout.write(msg + chr(8) * len(msg))
sys.stdout.flush()
sleep(0.02)

sys.stdout.write("DONE" + " "*len(msg)+"\n")
sys.stdout.flush()


This can look like this:

• You can also copy paste this next function to display a progress bar:

import time, sys

def update_progress(job_title, progress):
length = 20 # modify this to change the length
block = int(round(length*progress))
msg = "\r{0}: [{1}] {2}%".format(job_title, "#"*block + "-"*(length-block), round(progress*100, 2))
if progress >= 1: msg += " DONE\r\n"
sys.stdout.write(msg)
sys.stdout.flush()

# Test
for i in range(100):
time.sleep(0.1)
update_progress("Some job", i/100.0)
update_progress("Some job", 1)


This results in:

Solution:

I've found this two solution in the blenderartist forum:

• Print a text in the 3D view with the blf library
• Set progress information in the header area of a window via a modal timer
• In 2.69 an update in the api lets the user change the cursor appearance so we could change the cursor to the "loading" cursor.

What doesn't work:

• The solution of printing a progress bar in the console only work with windows.

This part of answer may contain errors

• Two of your links are dead. Can you elaborate with some code? – Banana Apr 20 '15 at 0:34