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.
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.
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?
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.
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;
(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.
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
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;
I’m trying to build up what I wanted but new stuff from you guys overflow my programmin skill
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.
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++ ){
guids.Add(this.GrasshopperDocument.Objects[i].ComponentGuid);
}
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.