nux95

Recognize c4d did finish loading

Jun 4th, 2011
183
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import  c4d
  2. from    time           import sleep, time
  3. from    threading      import Thread
  4. from    c4d.documents  import GetActiveDocument
  5.  
  6. def WaitUntilC4DDidFinishLoading(timeout = None, sleeptime = .5):
  7.     doc     = GetActiveDocument()
  8.  
  9.     if timeout:
  10.         startingTime    = time()
  11.     else:
  12.         startingTime    = 0.
  13.  
  14.     while True:
  15.         if doc != GetActiveDocument():
  16.             break
  17.  
  18.         delta   = (time() - startingTime)
  19.         if (delta > timeout) and (timeout):
  20.             return False
  21.  
  22.     sleep(sleeptime)
  23.  
  24.     return True
  25.  
  26. def main():
  27.     waitSuc = WaitUntilC4DDidFinishLoading()
  28.  
  29.     print waitSuc
  30.  
  31.     if waitSuc:
  32.         doc     = GetActiveDocument()
  33.         doc.InsertObject(c4d.BaseObject(c4d.Ocube))
  34.  
  35.         c4d.EventAdd()
  36.  
  37. if __name__ == "__main__":
  38.     t       = Thread(target = main)
  39.     t.start()
RAW Paste Data