As chen said, you would need to look into events.
The below will notify you when a new input is plugged into the X coordinate of a Construct Point, but then you would need to do some further work to subscribe to changes to that input and retrieve the value.
string _componentName = "Construct Point";
string _parameterName = "X coordinate";
private void SubscribeToComponentsAdded()
{
var doc = OnPingDocument(); // this gets the document in grasshopper, you probably need to do it differently with Rhino.Inside
if (doc == null) return;
doc.ObjectsAdded += Doc_ObjectsAdded;
}
private void Doc_ObjectsAdded(object sender, GH_DocObjectEventArgs e)
{
if (string.IsNullOrEmpty(_componentName)) return;
var matchingComponents = e.Objects
.OfType<IGH_Component>()
.Where(obj => obj.Name == _componentName);
foreach (var component in matchingComponents)
{
component.Params.ParameterChanged += Params_ParameterChanged;
}
}
private void Params_ParameterChanged(object sender, GH_ParamServerEventArgs e)
{
if (_parameterName == null) return;
if (e.Parameter.Name != _parameterName) return;
DoSomething();
}
I want to use an observer for my approach using the C# delegates / events. The hint with doc.ObjectsAdded += Doc_ObjectsAdded; has already helped me therefore.
I am now taking a brute force approach to wait for the GH_Document. As soon as this is instanciated i subscribe on ObjectsAdded.
In a further step, I subscribe to my own components.