Get the address of component B that A is connected to

Hi! I’m a student and I’m puzzled with a problem in my project for so many days.

Is there any way to build a special componentA to get the data from my chosen componentB, including the special parameter of it and where this component is linked to (the address of compoentC),? Only then can I do a recursion to get the whole relationship of this node network and construct a Directed Acyclic Graph.

I knew Metahopper can make it. But I have to make this in C# to make sure that it can work in my project.
It should work like this figure below:

It has already puzzled me for so many days!

Ps. I’m not a native English speaker. So if I speak something strange, please forgive me (lol)

If this means that you want a 100% C# solution … well … forget A to B (or to Z). Just post here what you have done and a very explicit description of your goal (i.e. is a Graph of some sort the target? or something else out of the Graph? etc etc).

1 Like

Oh, in fact I would like to know if there is some kind of API that can help to achieve the following requirements:

This algorithm should allow a particular grasshopper node to dynamically identify all the parameters of the node it is connected to, and output them. At the same time, it should allow to recursively get the parameters of all the nodes that follow the initial node (just like a chain) , the second node , the third node … one by one, in the same way.

Due to my poor English, these words are from Google Translate… Or if it’s still to hard to convey my need, maybe I can say it more shortly:
I know there are some nodes in MetaHopper that can help to read a group of Grasshopper nodes., and read their parameter input one by one. Now I need to learn how it works, so I can embed the algorithm in my vs project and build a similar node

Are you looking for something like this?

private void RunScript(DataTree<object> x, ref object Count, ref object Names, ref object Inputs)
  var firstInput = Component.Params.Input[0];
  var count = firstInput.SourceCount;
  var names = new List<string>();
  var inputs = new DataTree<string>();
  for(var i = 0; i < count; i++)
    var parent = firstInput.Sources[i].Attributes.Parent;
    if (parent == null) continue;
    if (parent.DocObject is IGH_Component)
      var comp = (GH_Component) parent.DocObject;
      foreach(var input in comp.Params.Input)
        inputs.Add(input.Name, new GH_Path(i));
  Count = count;
  Names = names;
  Inputs = inputs;
} (10.5 KB)


Ohhh Thank you! It did work!
But there is still a small problem remained and I do not know how to deal with.

It can only read the input of the component, and read the input of the input, etc. So the recursion can work to read the chain of nodes. But since the grasshopper nodes are arranged from left to right, so the best way is to read also from left to right, which means it would be better to read the output, the output of the output, etc.
But actually when I try to replace the Output with Input in the script, it came out that there are no nodes connected to the c# node as the output and the Output[2].ScourceCount is 0…But it’s clear that a gradient node is connect to the C port (output[2]) . But I cannot figure it out…QAQ

Try this:

private void RunScript(object x, object y, ref object A, ref object B)
  A = Component.Params.Output[2].Recipients[0].Attributes.Parent.DocObject;
} (7.9 KB)

Thank you sooooo much, it works well!
But there is still a problem left that
this.Component.Params.Output can work in c# script Component
but it cannot work in visual studio.

I try to construct a GH_Component object, but it turns out to be a abstract class and i cannot assign it, so I not get the Params of it…

So how can I make this in visual studio?

protected override void SolveInstance(IGH_DataAccess da)
  var recipients = new List<string>();
  foreach (var recipient in Params.Output[0].Recipients)
  da.SetDataList(1, recipients);
} (27.3 KB)

Thank you ! I hate my poor English that makes my words of appreciation pale and powerless. You really help me a lot.
And I feel happy that we have the similar habit of naming temporary Component as Meow~~

BTW, there is one last question, what’s your plugin that show the name of component on it? The plugin I’m using will make a big bubble box… Yours looks so good

Thank you!

Hello! Do you happen to know if the same is possible with ghpython?

a = ghenv.Component.Params.Output[2].Recipients[0].Attributes.Parent.DocObject (8.1 KB)

1 Like