algorithmic modeling for Rhino
I wish to accomplish a key/value storage component for grasshopper, and for this I would like to get the name of the output parameter object, that is connected to the input of my custom component. (So you can use the name of the output parameter to use as a key value).
Is this possible using the Data Access manager, or the SolveInstance part of the component? Is such reflection on the internal structure of a grasshopper component even possible? (Is it desireable?), what do you think?
Or, as a related question: is it difficult to create 'meta' connections, like the ones that are used by the timer and/or galapagos? Perhaps this would be a more structural solution to my problem.
Thanks,
Arend
Tags:
Hi Arend,
it's definitely possible, but you need to keep a few scenarios in mind, for example:
Information about input and output parameters for any component can be found inside the Params property of that component. The Params property returns the GH_ParamServer object which maintains all parameters associated with your component. Then, you can iterate over -say- Me.Params.Input and query information about the sources of each input parameter.
Another useful thing to know is the iteration counter in the IGH_DataAccess (DA) object passed in SolveInstance(). The first time (per solution) the SolveInstance() method is called the Iteration property on the DA object will be 0. For any subsequent call the counter will be incremented. This allows you to perform some basic testing and checking in case you need to, but only do it once.
Also, note that the 'name' of parameters and components is actually the NickName. The Name property of grasshopper objects is not supposed to be changed, but users can modify NickNames all they want. Typically users are only confronted with the Name of an object via the tooltips.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Hi David, thanks for the quick reply.
I can't seem to access the linked components:
When adding in solveInstance:
DA.SetData(0, this.Params.Input[0].Recipients.Count);
The result is 0, while there is an component linked, am I missing something? Is this the wrong way to access downstream components?
Thanks,
Arend
Ok, that was easy: I needed the Input[0].Sources
Ok, I've got a simple version working:
It bypasses the DA component alltogether, but seems to work nicely. I'm not sure if there are alternatives to accessing the Voilatile data of the source component; also I feel that the part of casting the strings is a bit hacky, but it seems to work.
Any comments are welcome.
Grasshopper doesn't support Dictionaries as data types, so unless you create a custom Data type that can be stored in a list as a Key/Value pair, no component will be able to consume your Dictionary<string, string>.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by