How can we do modelling works when running a 'backgroud' script?

@Jack_Zeng,

you might also subscribe to an idle event which does not fire when Rhino is busy. Below is a simplified example script which shows the current time in the statusbar, run it again to turn it OFF.

import Rhino
import scriptcontext
from datetime import datetime

def MyIdleEvent(sender, e):
    message = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    Rhino.UI.StatusBar.SetMessagePane(message)

def DoSomething():
    key_idle = "MyIdleEvent"
    if scriptcontext.sticky.has_key(key_idle):
        print "Time display OFF"
        Rhino.RhinoApp.Idle -= scriptcontext.sticky[key_idle]
        scriptcontext.sticky.Remove(key_idle)
    else:
        print "Time display ON"
        scriptcontext.sticky[key_idle] = eval(key_idle)
        Rhino.RhinoApp.Idle += eval(key_idle)
        
if __name__=="__main__":
    DoSomething()

I have not tried how it behaves if more complex scripts are fired from the event. In general try to leave the event as fast as possible, the event fires often !

c.