Grasshopper

algorithmic modeling for Rhino

Hi all,

I have a VB component that does a heavy computation. I want it to store the results the way a data recorder does and stop computing once the results are ready. Has anyone a clue how this could be done in VB, C# or Python?

Thanks,

Pirouz

Views: 1182

Replies to This Discussion

Why would you keep on computing once the results are ready in the first place?

I'm sorry, I don't understand what you're trying to do.

--

David Rutten

david@mcneel.com

Tirol, Austria

Hi David, 

The point is, even when computation is finished, the component (like any other component) consumes computation power and takes time, apparently because this is the way grasshopper can keep on previewing the results while they do not exit in Rhino yet? Please correct me if I'm mistaken. In any case, what I want is to store the results and, let's say, disconnect the inputs from the components, once the results are ready. Manually, I could put a Data Recorder component, and disable the main component once the container is not empty. 

The point is, even when computation is finished, the component (like any other component) consumes computation power and takes time, apparently because this is the way grasshopper can keep on previewing the results while they do not exit in Rhino yet? 

That's not how it works. Component solve themselves only once for the same inputs. The results are cached inside the component output parameter and they will not be recomputed until the inputs change (or maybe because you change the component options if there are any).

All data is cached, and when something happens (for example when you change a slider) then that slider and all components that depend on that slider will expire. These are the only components that are solved again.

Volatile data inside parameters can be converted into persistent data with the 'Internalise Data' option in the menu. Perhaps that's what you're looking for?

--

David Rutten

david@mcneel.com

Tirol, Austria

Thanks for taking the time to answer this David. 

My input data is a network of curves and it doesn't change during the whole process. I know I can internalize the outputs of my component (into the input of another component following it) and disable it afterwards (once it has finished its heavy computation process). All I want to do is to automate this as follows: Once computation is finished, keep them as persistent data and disable the component. Is it possible to do so from within my custom code? Let me ask my question differently: what is persistent data technically? How can I create an array or a list of persistent data?

Most types of Parameter contain two data trees, one for volatile and one for persistent data. Volatile data is destroyed whenever the parameter expires, it will then have to be recreated during the next solution. This can happen in several ways:

  1. If the parameter is hooked up to any sources than the volatile data of those sources will be merged into the volatile data of the parameter. This of course requires that the sources are solved first, but the plumbing of Grasshopper guarantees that.
  2. If the parameter does not have any sources, then the contents of the persistent data are copied into the volatile data. Persistent data is usually assigned by the user (via the Set One X, or Set Multiple X, or Manage X collection menu items) or it can be internalized. Persistent data is also written to and read from GH/GHX files, volatile data is not.
  3. If the parameter is an output parameter of a component, then it can have no sources and no persistent data. In this case, the component is responsible for assigning the volatile data to the outputs.

I think your problem involves case #3 right? You have a component which computes a solution once, and then you just want to keep pushing that solution into the outputs without ever recalculating, correct?

If so, it's strange that you'd have to do anything special, because the component should never recalculate anyway unless you change the inputs, which you just said you don't do.

However, you can store your results in some local variables, and then with any subsequent call to SolveInstance you just copy the cached results into the output.

Oh, are you building a GHA or are you using the scripting components? There's a different approach required for these.

--

David Rutten

david@mcneel.com

Tirol, Austria

Hi David, 

Yes my problem is related to case 3. "You have a component which computes a solution once, and then you just want to keep pushing that solution into the outputs without ever recalculating, correct?" yes exactly! I am in the last step of developing a GHA, but I wonder what the difference could be?

"However, you can store your results in some local variables, and then with any subsequent call to SolveInstance you just copy the cached results into the output." How can I do this technically in VB?

BTW, how would you interpret this from GH SDK on GH_Component..::..SolveInstance Method

"This function will be called (successively) from within the ComputeData method of this component."? 

Thanks for your time. 

You add a private variable to your component. Initially it will be set to Nothing.

Inside SolveInstance, you check whether this variable is Nothing. If it is, you do your computation and store the result inside your variable.

Next, you assign the variable to the relevant output parameter. I do not know whether you want to assign single values, or lists or datatrees, or how many outputs you want to assign.

You'll also only want to assign this cached data once, so you'll need to disable the gap logic and only assign your data during the first call to SolveInstance:

If (localData Is Nothing) Then
  'Create localData
End If

DA.DisableGapLogic()
If (DA.Iteration = 0) Then
  'Assign data
End If

--

David Rutten

david@mcneel.com

Tirol, Austria

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