How to calculate and display in real time while calculation in GHPython?

Hi @RetroPost.LT

you are exactly right, that’s how Kangaroo and other state-in-component add-ons (like Hoopsnake, etc) work.
They perform one (or a few) steps of the overall computation, and then they return the intermediate result. Once the solution is recomputed, if the starting value is not changed, they won’t use this value, but the intermediate value from earlier to carry on with computation.

In Rhino BETA/6 there is now a small alternative. It has Rhino update the UI, and that one will show a progress bar even “while” your computation happens. It has the disadvantage that Grasshopper is not meant to be run on multiple threads/from within events. So if you give any commands in between, they might have bad side effects. I am still showing this to give you an idea. (9.5 KB)

import Rhino
import rhinoscriptsyntax as rs

if activate:
    upper_limit = abs(x)
    Rhino.UI.StatusBar.ShowProgressMeter(0, upper_limit, "Python comp", True, True)
    for i in range(upper_limit):
        if i%10 == 0: Rhino.UI.StatusBar.UpdateProgressMeter(i, True)


Giulio Piacentino
for Robert McNeel & Associates