Grasshopper

algorithmic modeling for Rhino

Hello all,

I'm trying to disconnect specific sources from a (GH_Number) input parameter and instead to replace this data with my own computed elsewhere. I though this would be possible and easy by disconneting the source and setting the persistent data of the parameter, but GH just tells me that the input is failing to collect data. 

Here's what I tried:

IGH_Component c = C_Sof_Opt_MultiCore.GHDocument.FindComponent(guid); //this works

c.Params.Input[1].RemoveAllSources(); //this works
GH_PersistentParam<GH_Number> myParam = c.Params.Input[1] as GH_PersistentParam<GH_Number>; //this works

myParam.SetPersistentData(myData); //this doesnt do anything?

c.ExpireSolution(false);

GHDocument.NewSolution(false);

or else:

IGH_Component c = C_Sof_Opt_MultiCore.GHDocument.FindComponent(guid);

c.Params.Input[1].RemoveAllSources();
GH_PersistentParam<GH_Number> myParam = c.Params.Input[1] as GH_PersistentParam<GH_Number>;

c.Params.UnregisterInputParameter(c.Params.Input[1]);

myParam.SetPersistentData(myData);

c.Params.RegisterInputParam(myParam, 1);

c.ExpireSolution(false);

GHDocument.NewSolution(false);

I'm greatful about any pointers!

Views: 723

Replies to This Discussion

Hi Daniel

where are you trying to do this? The Grasshopper SDK does not allow this to happen at solution time. But you could make these adjustments at other points in time, for example from another form.

Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

What's the type of myData in the first block of code?

Also you should not be doing this during a solution. When is this code triggered?

Hi guys,

thanks for your replies.

@David: myData ist simply a list of doubles. Would I have to convert to a list of GH_Number first?

@David and Giulio: Out of curiosity, why is it a bad idea? 

How is it different from manually unplugging an input source and entering the values into the "set multiple numbers" field?

I thought of this as a very simple way to achieve a feedback loop. 

My solution:

Initial data -> SOLUTION -> adjusted data

After the fist computation, the initial (volatile) data is disconnected from the solution inputs. Instead, the adjusted data inserted as persitent data into my special input component (by finding the component in the document, as above). The solution then recomputes with the adjusted data.

I guess thinking about it now I could simply put the initial values into a separate input node.

I'll give this a go now but I guess I'll fall on my face yet again if the persistent data doesnt update...

oh I see what you mean now with doing this "during a solution":

I presume you mean that I am expiring components and forcing a recompute while I'm still inside the SolveInstance of a component?

How is it different from manually unplugging an input source and entering the values into the "set multiple numbers" field?

When you do it manually it doesn't happen during solutions. Because during solutions the UI is locked. 

I think if you supply a List of doubles, it uses the SetPersistentData(params object[] values) overload, and that indeed won't work.

To be absolutely on the safe side, I'd recommend getting the GH_Structure<GH_Number> from the PersistentData property and dealing with it directly.

Yes, you were right, converting my list of doubles to a GH_Structure first has done the trick.

As desired, the input is now disconnected, new persitent data is set and the solution recomputes using the new data. 

Following your comments about this not exactly being best practice has made me a bit nervous about this being the correct approach though. I'll see how it behaves in practice!

Many thanks!

For reference, here's the corrected code:

GH_Structure<GH_Number> data = new GH_Structure<GH_Number>();
foreach(double d in myData)

data.Append(new GH_Number(d));
}

IGH_Component c = GHDocument.FindComponent(guid); 

GH_PersistentParam<GH_Number> myParam = c.Params.Input[1] as GH_PersistentParam<GH_Number>;

myParam.PersistentData.Clear();
myParam.SetPersistentData(data);
myParam.RemoveAllSources();
myParam.VolatileData.Clear();

c.ExpireSolution(false);

GHDocument.NewSolution(false);

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

© 2023   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service