How to continuously output a value from the Grasshopper SDK

Hello,

I've recently started reading the Grasshopper SDK documentation and have successfully tested the "Hello World"(Simple Component (C#)) component which reverses a string.

At the moment I would like to continuously output a Point from my component. I'm guessing I can plug a timer to it and using a callback from the timer I can send a value to the output ? Would this be a good approach ? Otherwise, what's the recommended way of doing this ?

Also, I'm slightly confused, because the only way I saw how to output a value from the component was through the SolveInstance method which gets a IGH_DataAccess instance which in turn has a SetData method.

Is there any other way to get access to IGH_DataAccess . I was thinking I could create a reference local to my component and set to point to the instance passed from SolveInstance( if it hasn't been set before), but this feels hacky and I need to pass an input at least once. What would the best practice be ?

Thank you,

George

  • up

    David Rutten

    Using a timer is ok, but if your component always needs a timer, you should probably consider adding such a feature directly. This is what Kangaroo did a few months ago and it's a much neater solution.

    Do note that Grasshopper wasn't really designed to be a continuous solver. If you want to turn it into one you have to be careful about not blocking the UI thread all the time which turns the software unresponsive.

    There's no way to get an IGH_DataAccess instance outside of SolveInstance. The DA instance is created specifically for a single solution and it is not guaranteed to remain valid.

    The best way of doing this is to schedule solutions. GH_Document exposes methods for scheduling and you can register callbacks for when a schedule starts. In this callback you can expire your component which will ensure that SolveInstance() will be called again. Schedules that are started during solutions will come into effect when the solution completes. Thus, if your solution takes 1 second to complete and you keep scheduling solutions with a delay of 100 milliseconds, then all solutions will be roughly 1.1 seconds apart. I.e. the schedule time refers to the time in between solutions, not the time from the start of one solution to the start of the next.

    --

    David Rutten

    david@mcneel.com

    3