algorithmic modeling for Rhino
Hey everyone,
quick question. If i write a struct in a c# node in grasshopper, is it possible to return my struct ergo set A = mystruct; and use that data further down stream?
I know that it will return it with the output saying something along the lines of "Script_Instance+mystruct" which is fine, but how do i access the properties of my structure?
If i plug this output into a new c# node. this new node essentially doesn't understand this data type... which honestly i expected. But is there a way for me to define a struct in one node that can be seen by all nodes?
or am i basically getting to the point where i need to define my own library... which honestly i have very little experience doing?
I think i just found a box with "Pandora" written on it, and like a 5 yr child... i opened it.
M
Tags:
Hi Mario,
as you expected types defined in one C# component aren't available to another. Here are some possible workarounds:
If your struct is relatively simple then you can probably make a string representation of it. The benefit of this approach is that it is easy to generate a string so you could even do it by hand. Downside is type-safety and you'll spend some cycles on formatting/parsing the string on both ends.
A byte-array will be faster to write and read, but it is not humanly readable so it's harder to debug.
SortedList and SortedDictionary are also possibilities. A bit more type-safe than strings, code will be more readable but casting probably still required.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Very interesting topic. I have tried to do the same thing – to pass custom created objects between C# components. What I have ended up doing is exactly what David just proposed – to create a list of string-arrays (as a substitution for objects) containing the information I wanted to pass. Basically, I wanted to store meta data in a line object, so I created an array for each line with all necessary information about the line’s geometrical properties (like start x,y,z, end x,y,z etc) and just added on the additional information in the end of that array. Quite brutal, but it works.
The reference library idea seems cool though. Never thought of that.
I guess an even more sustainable approach would be to create a gha-file defining a bunch of components, which all are compiled from the same visual studio project (where the custom classes also are defined). Like the karamba guys have done for passing their beam objects between different components. So, are there any example on how to create components in a gha solution, with custom objects as output / input?
Cheers,
Emil
For GH2 I will add a global code area where you can type code that will be shared amongst all script components within a single file. I haven't quite figured out the best way to do this, but it must be possible.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
David,
This will be a useful addition - thanks!
Any chance that there could be way of including a custom struct as a part of goo?
I'm actually trying very hard now to get rid of the 'goo ideology' in GH2. I'm hopeful that I'll be able to remove all type constraints on data trees. This is definitely much harder for me than insisting on a Goo interface, but it will make using custom types much easier for 3rd party developers.
One particularly difficult aspect of this is Custom Data, which should be assignable to all data in Grasshopper. Without a Goo interface this is not possible on the data itself (you cannot add any extra data onto a System.Boolean, no matter how hard you try), so I'm in the middle of writing a huge amount of double-entry-bookkeeping code which maintains parallel datatrees with custom data. You could use this custom data both via code and via the GH interface, but I'm only supporting a limited number of types because I need Custom Data to be immutable, and that becomes impossible to control if people can add their own types*.
* There's a possible exception for enums and structs, I may look into this at some point.
David,
Your vision and goal is appreciated - good luck with the work.
Clearly there are work arounds if structs don't exist. I've just found them extremely useful for writing cleaner code in the GH environment (helps reduce the number of things to keep track of when they can be packaged and passed around), so if that concept is made available in some way I think you'd have a winner addition to GH2
You're doing great work, and i appreciate all the help you provide on this forum. Grasshopper has been my entry point into all things coding. Its been a fun rabbit hole to fall down.
Keep on going! and let me know if you ever need another hand for the (hopefully) future Mac development (objective C is the shit!)
M
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by