Getting and setting values to GH Player’s input components with C#

I’m trying to achieve something similar to the Hops component in Grasshopper within my own C# code. I would like to detect input components, change their values and display the geometry without opening the Grasshopper or running the GH Player.
I found out how to get access to the instance of the GH_Document from the file and I figured out how to detect the input components. I started to play around with the “Get Number” and I have some difficulties reading and setting the values. For example, I can detect how many instances of the component there are in the GH Canvas and I can read properties such as Prompt, AtLeast and AtMost. Unfortunately, I’m not sure how to get other values such as Minimum, Maximum, Presets and the currently stored values. In the picture below, number of values is 0, even with the Sliders.


So, I’m wondering what is the best approach here? I’m missing something when I try to read the values and I’m not sure at the moment how to set them. Also, what is the best practice for retrieving the geometry – can I simply use the CollectData method and access it using the VolatileData property?

This is the code that I have at the moment:

public static GH_Document GHDocumentFromPath(string filePath)
if (string.IsNullOrEmpty(filePath) || string.IsNullOrWhiteSpace(filePath))
return null;

GH_DocumentIO io = new GH_DocumentIO();
GH_Document ghDoc = io.Document;

return ghDoc;

public static void FindContextualComponents_GetNumber(GH_Document ghDoc, out List<ContextualComponents.GetNumberParameter> cxContainers)
List<IGH_ActiveObject> allActiveObjects = ghDoc.ActiveObjects();

cxContainers = new List<ContextualComponents.GetNumberParameter>();

foreach (IGH_ActiveObject ao in allActiveObjects)
if (ao is ContextualComponents.GetNumberParameter)
ContextualComponents.GetNumberParameter cx = ao as ContextualComponents.GetNumberParameter;

if (cx != null)

public static void GetValues_GetNumber(ContextualComponents.GetNumberParameter gn,
            out string prompt, out int countMin, out int countMax, out List<double> numbers)
            prompt = gn.Prompt;
            countMin = gn.AtLeast;
            countMax = gn.AtMost;
            //double min = gn. //TODO: get min value
            //double max = gn. //TODO: get max value
            //List<double> presets = gn. //TODO: get presets

            numbers = new List<double>();

            DataTree<GH_Number> ghNumbers = gn.ContextualDataTree;

            if (ghNumbers != null && ghNumbers.BranchCount > 0)
                foreach (List<GH_Number> list in ghNumbers.Branches)
                    foreach (GH_Number item in list)

Thank you in advance!

Does something like this work for you? I’ve modified your GetValues_GetNumbers method.

public static void GetValues_GetNumber(IGH_ContextualParameter gn,
    out string prompt, out int atLeast, out int atMost, out List<object> numbers)
    prompt = gn.Prompt;
    atLeast = gn.AtLeast;
    atMost = gn.AtMost;
    var data = new List<GH_Number>();
    data.Add(new GH_Number(3.0));
    numbers = gn.ContextualData.ToList();
1 Like

Hello Andy,
Yes, this worked! Thank you very much!

However, I had difficulties simply reading the values before using the AssignContextualData method. So, If understand this correctly, I need to assign some values to the GetNumber in the first place and then read them. It is not possible to simply get the values before assigning anything (when there are sliders), or is it?

Also, it would be really helpful if you could tell me how to get other properties of this component such as Minimum and Maximum. I tried to find the documentation for this, but at the moment I’m simply exploring everything within Visual Studio with the autocomplete.

Thank you again!