algorithmic modeling for Rhino
Hello,
What should the DA.GetDataList call be when passing a dictionary or sorted list into a component? I haven't had much luck.
Standard lists work like this:
if (!DA.GetDataList<RecognizedClassTypeHere>(0, variablename)) { return; }
Dictionaries (as below) don't seem to work...
if (!DA.GetDataList<RecognizedClassTypeHere, RecognizedClassTypeHere>(0, variablename)) { return; }
What should it be?
Tags:
Parameters only support items, lists or trees, you cannot add dictionaries (or other collections such as hashsets, stacks, queues, hashtables) to this.
You can pass dictionaries between components, but you must put those dictionaries inside some type of Goo, and then treat them as items.
When outputting dictionaries:
Dictionary dictionary = MakeADictionary();
IGH_Goo dictionaryGoo = new GH_ObjectWrapper(dictionary);
DA.SetData(0, dictionaryGoo);
When inputting dictionaries:
GH_ObjectWrapper dictionaryGoo = null;
DA.GetData(0, ref dictionaryGoo);
Dictionary dictionary = dictionaryGoo.Value as Dictionary;
if (dictionary == null)
throw new InvalidCastException("Data wasn't a Dictionary");
(I typed the above without testing any of it, there may be mistakes, I just wanted to show the basic concept of sharing custom data types).
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