Skip to content

Instantly share code, notes, and snippets.

@Durman
Created January 21, 2022 17:30
Show Gist options
  • Save Durman/84f6e897020f8110177547950f80d3cd to your computer and use it in GitHub Desktop.
Save Durman/84f6e897020f8110177547950f80d3cd to your computer and use it in GitHub Desktop.
Examples of creating a progress bar in Blender

Showing progress bar in Blender

Main problem of showing progress bar in Blender UI is that while a script is running the UI is frozen. So the simplest (?) solution is to break execution whenever the progress status should be updated. For this you can use either timers or modal operators. The last one can't be switched on during all time of Blender execution and has some starting costs.

import bpy
from functools import partial

def show_progress(area):
    if show_progress.iteration >= 100:
        area.header_text_set(None)
        return
    else:
        area.header_text_set(f'Loading {show_progress.iteration}%')
        show_progress.iteration += 0.5
        return 0.01

show_progress.iteration = 0
bpy.app.timers.register(partial(show_progress, bpy.context.area))

progress bar1


@ranjian0
Copy link

ranjian0 commented May 3, 2023

A pretty decent solution. Gave me some other nice ideas. Thanks!

@hkunz
Copy link

hkunz commented Jan 11, 2024

this doesn't work if you have a subprocess.run(command) running

@ZeroGravitasIndeed
Copy link

Novice question: how would one feed the text to be shown to such function, from inside an operator class? I have an add-on that loops through a lengthy list, and I'm trying to apply this but I'm not getting anywhere (it must be something obvious, but…).

@SuzukaDev
Copy link

Novice question: how would one feed the text to be shown to such function, from inside an operator class? I have an add-on that loops through a lengthy list, and I'm trying to apply this but I'm not getting anywhere (it must be something obvious, but…).

Haven't tested, but what I'd try is the following:

First, the place to show your variable/message is:

area.header_text_set(f'Loading {show_progress.iteration}%')

Since bpy.app.timers.register(partial(show_progress, bpy.context.area)) is registered once, I'd guess we can not pass a parameter with our variable/message. So, what I will try is to have a global variable with your message. You edit/update that variable in your code as you want.

And then:

global my_message
area.header_text_set(f'My Message: {my_message}')

In theory will get it and print it. (Again, not tested but is what I'd try)

@ehsanwwe
Copy link

ehsanwwe commented May 2, 2024

simple and nice idea , can i ask a question ,are you submit this topic or git in google webmaster tool ? because it was first suggestion of googles in all of my search about Progress bar Python Blender

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment