Grasshopper

algorithmic modeling for Rhino

Can external events (ie a remote server) trigger RunScript() output in GH C#? I'm hoping to implement a web API in a C# script, which pushes updates to the script.  Dynamically passing variables from <custom additional code> events to RunScript(ref object whatever) seems like it would require an alternate signature for invocation.  I've tried several approaches, but nothing worked:

a) I can't call RunScript() from custom code (Even with infinite-loop-protection), and

b) I can't get RunScript() to see updated variables without changing the inputs to the GH object.

This seems to be by design.

Alternately, could this be accomplished with an output --> input loop back? Is there an implementation of delegates that might work? Is constant polling from RunScript() the only way, and if so, isn't that cumbersome?
Or, would I need to ditch this approach, and import separately from the whole C# Script?

Big thanks, Bohmwave

Views: 1089

Replies to This Discussion

I think defining a delegate to call ExpireSolution() is the way to do this. My handle on events is iffy at best - maybe dig around in some of these threads:

http://www.grasshopper3d.com/forum/topics/non-blocking-c-plugin?com...

http://www.grasshopper3d.com/forum/topics/threads-expiresolution-pr...

http://www.grasshopper3d.com/forum/topics/how-does-read-file-watch-...

I assume you either have an event handler that is triggered by a remote event, or you have a delegate or callback which is invoked. Either way inside this methed which is called (indirectly perhaps) by your server, you have to expire your script component. If you call Component.ExpireSolution(true); it will trigger a new solution and your script will run anew.
Incidentally, if these external events can come in during grasshopper solutions, specifically if they come in on another thread, you have to make sure that you call ExpireSolution on the Grasshopper UI thread. Is this the case?

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service