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();
io.Open(filePath);
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)
cxContainers.Add(cx);
}
}
}
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)
numbers.Add(item.Value);
}
Thank you in advance!
Ognjen