Hi everyone,
I’m just testing the V8 Script Editor.
I’m splitting up my code into several individual C# files and refernce the classes and methods in my “Command Scripts”.
I added the common C# Classes as .cs files to the Shared folder in the project.
How do I reference the classes in my scripts, that actually are run as commands?
Example:
How do I call a class that is defined in “dbaGeometry” from “dbaShowParquette”
Best,
Martin
Hey Martin
Did you ever find out about this?
Thanks!
Hi, you need to compile the shared file into a DLL.
Huh, can you give a bit more detail on this or suggest an easier way?
I find myself wanting to just create one long monolithic C# script in that case
Thanks in any case
Hi, while I think it is not possible, even if it is possible, it is not going to work as you think.
Let’s say you have two C# nodes.
example1
example2
And let’s say you have a shared file defining a class named ‘sharedclass’
shared.cs
If referencing an external source file is possible (I assume it is not), example1 and example2 will both contain sharedclass. But that sharedclass is compiled separately twice. Between example1 and example2, there are classes that have the same names, same member functions, and member variables. However, they are treated as different classes. So, for example, when you pass an instance of the ‘sharedclass’ from example1 to example2, you cannot read it from within example2 because there is no definition of the ‘sharedclass’ defined in example 1.
This all means it is essentially the same as copying and pasting the shared code into example1 and example2. To share the definition, sharing code is not enough, you need to compile the shared code into DLL and share the DLL between multiple components.
Thank you for getting back to me Mikity. I understand your points. Still a few questions, maybe I am missing somthing.
- How about referencing a class from example1 in example2?
- I dont seem to be able to reference anything from the .cs in the Shared folder at all, do you need to add a common namespace or somthing?
Hi, I didn’t notice you were talking about the script editor running on Rhino. What I know is about the script editor running within Grasshopper. So, there is a chance that below that does not apply to your case.
However, referencing separate source files as text files is not supported in C#. So you need to either
- compile the shared files into DLLs and reference them from multiple scripts.
- compile multiple .cs files into a single assembly. (note that this is different from referencing separate source files as text files)
To do 1, you need to compile the shared files outside Rhino manually.
2. should be theoretically possible, but I never heard the programming environment built in Rhino does that. (was it possible in Rhino v7?)
If both are not possible you need to
3. copy and paste the shared code into each script.
which always works. But I assume you are asking whether there is a smarter way.
1 Like