Grasshopper

algorithmic modeling for Rhino

 

Hi,

 

I've had a user request for my plugin to acknowledge a computation abort request when the user presses escape.  I'm assuming there is probably an event raised, and that I'll have to spawn a worker thread to do the calculation.  Is this possible and is there any examples of achieving this?

 

Thanks in advance,

 

Jon

Views: 994

Replies to This Discussion

Hi Jon,

 

I don't get it, are you looking to abort the solution or are you looking to abort your portion of the solution if an Escape has been pressed?

 

Have a look at the following methods, see if it helps you out:

 

GH_Document.RequestAbortSolution()   (this sets the abort flag to true)

GH_Document.AbortRequested             (gets the value of the abort flag)

GH_Document.IsEscapeKeyDown()        (static/shared method to test the state of Escape)

 

Don't call IsEscapeKeyDown() too often, it does take some cycles to measure it. Also, it will print a message in the command line if it is down ("Escape key abort"). Furthermore, it will only work if the Grasshopper window has focus. I don't want to respond to Escape key presses that happen in other application while Grasshopper is churning away.

 

 

When an Abort has been requested, Grasshopper will not solve the next object in the queue, and it's possible that specific objects also handle this logic inside their own Solution methods (Components for example check the Escape state while they iterate over their data).

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Hi David,

 

That's helpful, I'll test it shortly.  Some of my force density and mesh inflation routines can take a minute (or longer) to converge on a solution for larger inputs, so I'm looking to stop my computation within it's iteration.  The GH_Document.AbortRequested should be sufficient.

 

Cheers,


Jon

AbortRequested only returns True if someone calls RequestAbortSolution(). It doesn't happen automatically. There's basically no event I can reliably handle to catch an escape press. I need to check the asynchronous state of the Escape key periodically to see if it's been pressed since the last time I called it.

 

If you're looping inside a component, you'll need to test the escape state yourself every now and again, then request an abort and exit your algorithm.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service