+ Reply to Thread
Results 1 to 2 of 2

Thread: Cancelling script by 'Esc'

  1. #1

    Cancelling script by 'Esc'

    Hi,

    Cancelling scripts seems possible via VbScript by hitting 'esc' (Rhino.sleep(0)). I tried the same technique with python (rhinoscriptsyntax.Sleep(0)), and rhino eventually hanged-out. Is it possible to cancel a script with a different way?

    The main reason for doing this is because I sometimes can't imagine when the script will end,
    when doing form finding. It will be good if I can decide when to stop while looking the results. Maybe multi-threading?

  2. #2
    Senior Member Steve Baer's Avatar
    Join Date
    Apr 2010
    Location
    Seattle
    Posts
    1,472
    Blog Entries
    19
    All of the RhinoScript functions check to see if the escape key was pressed and abort if it was. I didn't want to add this overhead to the python implementation for every function, so I decided to break this out into a separate function that you can call when you actually want to check for the escape key. The function is called escape_test and is defined in the scriptcontext module.
    https://github.com/mcneel/rhinopytho...riptcontext.py

    Python Code:
      import scriptcontext
       
      x = 0
      for i in xrange(100000):
          x = x+i #pretend this is a long running loop
          scriptcontext.escape_test() #will throw an exception if the escape key was pressed
       

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts