How to send C# class another components

I want to make a particle class that moves every second.
However, I don’t know how to exchange data within a class between components.
Is this a bad type specification?

—1st Components -----

List<Particle> particles = new List<Particle>();

for(int i=0; i<_pTotal; i++)
   var tmp = new Particle();
   Vector3d v = new Vector3d(1,1,1);

A = particles;

—2nd Components -----
this code is error…

A = _p[0].getPos();

My Grasshopper file is : (11.1 KB)

Hi Fumi Anzai
You need to use reflection,like this (11.3 KB)



Thanks your time and reply.
I didn’t understand about reflection in C#.
Your sample files are very helpful.
Thank you very much for your valuable response !



Today , I study reflection in C#.
Then I tried to create some functions and proceed.

bool getState(int _i)
   var types = _p.Select(p => p.GetType().GetMethod("getState")).ToList();
   bool b =  (bool)types[0].Invoke(_p[_i],null);
   return b;

It is not possible to know the number of arrays
like a …


and …
It takes time to learn how to write Invoke with arguments.
Is there any other way than C# reflection ?

Particle p = (Particle)_p[0];

Is it possible to cast like the above?
Please your advice.



Thanks your addvice !
I try your link of topics too.
using anonymous method and dll.


the reason why you cannot pass classes from one script component to another is due to the fact that it does not know the exact type because it’s missing the right ‘using’ reference…

Any script component has a name with a unique ID. Something like (…)ScriptComponent325346346346(…)MyClass… i believe

Now you can try to find that. It’s in the memory and accessible. Maybe I’ll can try to give an example later, or you are using Tuples and Func<>/Action<> delegates to be passed over. Last but not least you can use Reflection, which is in use by both examples… This is terrible for performance critical use-cases like ‘Particles’. There is also a couple of boxing and unboxing going on if you work with ‘object’.

However, something to note: Generally seen it is about making a bad hack in any case. Write a custom plugin or a library instead, and access your object directly from there…

1 Like

Thanks your reply and time!
Your comment was very helpful :grinning: