Change Contents of a ValueList based on selection in another ValueList

Say I have a valuelist that has two choices: meats and vegetables (just fun examples, the choices can be anything).

If meats is chosen in the first valuelist, then I’d like the second valuelist to be populated with a list of meats, but if vegetables is chosen, then I’d like the second valuelist to be populated with a list of vegetables.

Is this possible? If so, can someone give me a rough idea of how to go about it (I’m trying to figure out how to do it with a C# component, but no luck so far).

Have you tried ItemSelector component from Human plugin?


ItemSelector.gh (16 KB)

private void RunScript(string x, object y, ref object A)
{
  if (x == _prev) return;
  _prev = x;
  if(x != "Meats" && x != "Vegetables") return;
  var sources = Component.Params.Input[1].Sources;
  if(sources.Count != 1 && !(sources[0] is GH_ValueList)) return;
  var vl = (GH_ValueList) sources[0];
  vl.ListItems.Clear();
  vl.NickName = x;
  foreach(var item in ((x == "Meats") ? _meats : _vegetables))
  {
    var vi = new GH_ValueListItem(item, item);
    vl.ListItems.Add(vi);
  }
  vl.ExpireSolution(true);
}
// <Custom additional code> 
string _prev = "";
string[] _meats = new string[]{"Red Meat", "Poultry", "Pork", "Seafood"};
string[] _vegetables = new string[]{"Leafy green", "Cruciferous", "Marrow",
  "Root", "Edible plant stem", "Allium"};
// </Custom additional code> 


ItemSelector.gh (12.9 KB)

3 Likes

Hey thanks for the solutions. Sorry for the delay in responding. Covid nonsense got me sidetracked. Then work!