Grasshopper

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

 

Views: 2084

Replies to This Discussion

Hi Arend,

 

it's definitely possible, but you need to keep a few scenarios in mind, for example:

  • A parameter can be connected to any number of sources.
  • A source might have any name, including a zero-length string.
  • It is not standard procedure to make the behaviour of Component X dependant on the state of other components, you need to communicate this breach of protocol to your users.
  • Sources may change during IO operations. While a gh/ghx file is being read (this happens both during opening, pasting and sometimes during undo/redo) all parameters will be connected to 'ghost' sources. Only after the entire network has been deserialized, will the ghost sources be replaced with the actual sources. Basically this means you need to be aware of the state context of your code, so that you don't do things at the wrong time. If you only ever operate within SolveInstance() you should be fine though.

 

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:

http://pastebin.com/LmiZJNBM

 

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

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service