Get parameter value from Param.Input

Hello, I was wondering if there is a way to programatically (C#) collect the numeric data from a given input? For example, you can obtain an input source’s nickname using the following expression:

Is there a way to do something like this?

I realize that it’s probably not that simple since the input components could be of different types (see image below) but I was wondering if there was a general way to (1) determine if the input value is a number, and (2) if so, what’s its value? Can someone point me in the right direction?


Hope this help:

private void RunScript(DataTree<int> x, ref object A)
  A = Component.Params.Input[0].Sources[0].VolatileData.AllData(false);
} (3.5 KB)

1 Like

Thank you for your answer! It does seem to work but is there a way to convert the resulting IGH_StructureEnumerator data type to a regular numeric data type (double, float, decimal,…) so that I can use the resulting number in other calculations?

private void RunScript(DataTree<int> x, ref object A)
  var ghNumbers = Component.Params.Input[0].Sources[1].VolatileData.AllData(false);
  var numbers = new List<int>();
  foreach(var ghNumber in ghNumbers)
    int number;
    if (GH_Convert.ToInt32(ghNumber, out number, GH_Conversion.Both))
  A = numbers;
} (4.6 KB)

1 Like

Hi @sofia.feist in that case you’ll need to iterate the IGH_StructureEnumerator and cast the IGH_Goo to the input type. Here’s an example (5.1 KB)

private void RunScript(List<int> x, ref object A)

    int integer = new int();
    foreach(var item in Component.Params.Input[0].Sources[0].VolatileData.AllData(false)){
      item.CastTo(out integer);

    Print(integer.GetType().ToString()); // returns System.Int32
    A = integer; 
1 Like

I thought you could just cast the entire VolatileData to a GH_Structure<GH_WhateverType> ?

GH_Structure<GH_Number> tree = Component.Params.Input[0].Sources[0].VolatileData as GH_Structure<GH_Number>

Thank you all for your answers! They work and they really helped!

Just some further remarks

  • If you want to collect just all the data in input, it’s Component.Params.Input[0].VolatileData.
  • If you cast with “as”, test for nullity. Casting can fail, and will if you have variable data types, you would want to handle those cases somehow (Ignore bad data types? Throw an exception?)
  • You might want to test what happens if you internalise data in the parameter
1 Like