Find inputs of a component and managing its data

Hi all,
I’ve searched everywhere but I couldn’t find a solution to my problem, sorry if its a duplicate. (5.4 KB)

In c# we can find inputs param with “this.Component.Params.Input[0].Sources[0]” etc.
Is it possible to do the same thing with any other component? (not only the script component itself)
To count its inputs/sources to “go back” even more in the canva…
(in the attached definition I show 2 “methods”, it should be easy to understand… what I did wrong? >_< )

Also, how can I “copy” or manage a whole data tree from a “Data” component to another.
(Referring to attached file) Like copying the content of “DataABC” to “Data123” and internalizing it.

Thank you in advance for any reply!

Is it possible to do the same thing with any other component

Of course. Just as how you operate the script component itself.

how can I “copy” or manage a whole data tree from a “Data” component to another.

You can code sth like


… and internalizing it.

If “Internalizing” refers to internalize a referenced param, there is no simple and documented way to do that as far as I know. I use the reflection in my plugin.

Ok… but my best approach was that in the attached definition. :sweat_smile:
I can (easly) find nickname of the first input/source (Data123), but i can’t find the same of its input param/component (DataXYZ).

And regarding “copying” and internalizing data… i’m still trying to understand and apply your reply.

I think for single parameters you can keep going on with Sources, e.g.

this.Component.Params.Input[0].Sources[0].Sources[0] etc.

Where it becomes more tricky is when you hit an output parameter of a component and want to keep going on further upstream, as you have to find the component which owns this parameter, then go through its input parameters again… But somehow looks to me as if this wasn’t exposed publicly or if a IGH_Param just doesn’t know which component it is owned by?

1 Like

Omg, it was so simple… thank you! This is already something great for me.

Exactly my problem. By using “GrasshopperDocument.FindComponent” with Guid, GH doesn’t retrieve a working component object to work on.

sounds you are trying to find a workaround for a workaround for a workaround. What’s your actual problem?
You can always loop through all components on the canvas for yourself and compare nicknames or other properties. Unless your definition has more than 10000 components, this is not even bad performing.
If you want to optimise this by going upstream, you need to this recursively.
Internalisation: As @gankeyu said, its not well documented on how to internalise data, at least I cannot remember doing this. You can however “serialise” data. I never did this through a script component, but you might search the forum on how to do this with custom components, since I can’t remember the exact workflow.

1 Like

Indeed, you’re right …
I’m just tring to make a c# component that stores data in a “Data” component it find just above itself.
Only if it doesn’t have an input params linked and:

  • is empty or
  • doesn’t have already the same exact content of the upcoming content to the c# script;

So it will be a “data dam” that refresh (expire) only when needed.
(actually old stuff but i’m stubborn)

(If i move fast it get far enough to detach)
I can found some properties of a not-linked param, like its nickname… but I cant know if it already have input sources and such.
Here is why I wanted “Input[0].Sources[0]” of a component found by guid.

does this help? (7.6 KB)

  private void RunScript(object data, string receiverName, bool hasChanged)

    if (hasChanged)
      Grasshopper.Kernel.Parameters.Param_GenericObject receiver;
      receiver = (Grasshopper.Kernel.Parameters.Param_GenericObject) FindComponent(receiverName);
      if (receiver != null)
        foreach (IGH_DocumentObject bj in receiver.Recipients)


  // <Custom additional code> 

  IGH_DocumentObject FindComponent(string nickname)
    for (int i = 0; i < GrasshopperDocument.ObjectCount; i++)
      if (GrasshopperDocument.Objects[i].NickName.Contains(nickname))
        return GrasshopperDocument.Objects[i];
    return null;

IGH_Attributes.GetTopLevel.DocObject gives you the component an embedded param belongs to.

But here the param is a floating one (IGH_Param.Kind), it is a top level object itself


My reference to internalizing here is about internalizing a referenced geometry. If it is a primitive type (number, string, etc), you just need to copy the data and add it to PersistentData

Ah cool, works, no idea what this would be useful for, but works :wink:

var paramA = this.Component.Params.Input[0].Sources[0];
A = paramA.NickName;

var paramB = paramA.Sources[0];
B = paramB.NickName;

var compC = paramB.Attributes.GetTopLevel.DocObject as IGH_Component;
C = compC.NickName;

var paramD = compC.Params.Input[0].Sources[0];
D = paramD.NickName;

1 Like

I’m trying to build up what I wanted but new stuff from you guys overflow my programmin skill :laughing:
I didn’t understand Keyu Gan’s reply at first, now you made it idiot-proof.
Thank you guys! This is exactly what I was searching for.
I’ll keep this updated.

seems to work like this, have you even opened the gh file? It passes the data from one component to the other without a wire in between.

My bad :joy:

Yest, that’s great, it works.
But still I havent managed to get "Params.Input[0] etc " to work for a component that is not the c# itself or something linked to it (or linked to something linked to it, etc)
I mean, a completely unlinked/unwired component.

The “this.GrasshopperDocument.FindComponent” function give always a broke object where "Params.Input[0] etc " doesn’t work… or maybe i’m feeding it wrong Guids.

int cycles = this.GrasshopperDocument.Objects.Count;
List<Guid> guids = new List<Guid>();
for (int i = 0; i < cycles; i++ ){
A = guids;

This gives me a list of all Guids of the current grasshopper file.
But, every type of new param i create (Data,Int,Curve, etc) have the same exact Guid! Is this normal?
Maybe this is the problem… i was going mad.

Should I use InstanceGuid?

You should use InstanceGuid instead of ComponentGuid. ComponentGuid is used to clarify what type the object is. InstanceGuid is a unique identifier

1 Like