Finding GUID of connected component

I am currently attempting to get the id of every component connected to a specific one. I currently have this, but the results don’t add up:
This component’s guid: GH_Component a; a.instanceGuid
The Guids of components connected to a’s outputs:

 foreach (IGH_Param inputGhParam in a.Params.Output) {
    foreach (var dest in outputGhParam.Recipients) {
      System.WriteLine(dest.InstanceGuid); //<- this gives me odd results
//It returns GUIDs but none match any of the others a.instanceGuid
    }
}


What is outputGhParam?

This piece of code prints the nickname of every component connected to source 0:

private void RunScript(DataTree<object> x)
  {
    foreach( Grasshopper.Kernel.IGH_Param param in this.Component.Params.Input[0].Sources ){
      Print(param.Attributes.GetTopLevel.DocObject.NickName.ToString());
    }
  }

Replace “NickName” with “InstanceGuid” and et voilà.

The “structure” is that each component have parameters, maybe you stopped at the parameter.

ComponentA <> OutputParameter <> wire <> InputParameter <> ComponentB

With .Attributes.GetTopLevel.DocObject you “step up” from a parameter to its component.

1 Like

Thank you, this was what I needed =)

here it is in Python:

from ghpythonlib.componentbase import executingcomponent as component
import rhinoscriptsyntax as rs

class MyComponent(component):
    def RunScript(self, O):
        return self.get_name()

    def get_name(self):
        names = []
        for obj in self.Params.Input[0].Sources:
            name = obj.NickName  # or obj.Name
            names.append(name)
        return names