algorithmic modeling for Rhino


I am unfamiliar with C# but am trying to script a component that uses commands from a non-rhino library. The library is from a analysis program called STRAND7. Until I have linked the library I cannot use the commands I need to activate the program remotely (via its API). The library is a .cs file and I believe I am just suppose to "add" it to the component. This has proven difficult via " manage assemblies" since I keep getting an error code saying it was unable to load it.

Am I missing something? I have tried copying over the file and placing it in the "additional code" area but I end up getting a heap of error messages that way too. 

Thank you so much!


Views: 5696


Replies to This Discussion

*.cs is C# source code. Libraries have the *.dll extension and are compiled. If it's C#, you can just copy/paste the code into the <additional> portion of the C# component.

Well, looking at the source, you can't just copy it, it contains using statements at the top for which you may need to find dlls in the GAC to import. I can't remember now whether Interop is a default loaded namespace.

Also the code imports C++ methods via DllImport statements, which means you may need to direct the code towards the St7API.dll file.

Good grief... that's one hell of an unfriendly API to work with. I do not envy you.

I know right! - but it will be worth it

Dear David, 

Thanks for replying. Based on youre response I have a further question:

1) Since I cannot include using statements in the "additional code" area, is it possible to extend the number of 'using' libraries of the component itself  ie the grey area at the top of the script which cannot be edited? I assume these area filled based on compiled libraries situated somewhere in grasshopper installation folder. Would it be possible to compile my .cs code into a dll and add it there/ or could I just add the dlls the two additional 'using' statements are referring to?

the using statements at the top of a c# script component are dictated by the assemblies you've referenced in. right click the component and choose "manage assemblies" and then add a reference to the dll you want to use - all the namespaces in it will automatically be added as "usings."

thank you. I will try that now!


I had difficulty attempting the solutions that were suggested here. However the solution I eventually used was:

1) copy the code i needed into the " additional code " area of the C# component

2) delete the 'using' statements ONE AT A TIME

3) closed the editor to see the errors that came up to identify which commands needed the 'using statement' i just deleted

4) manually changed the commands which relied on the using statements to include system.whatevertheusingstatementwas - eg the command 'StringBuilder' relied on the using statement 'Text' thus i changed 'StringBuilder' to 'System.Text.StringBuilder' and the thing worked. 

5) Repeat for each of the using statements you need to delete.

this might have just worked for me because luckily the dlls I was referencing seemed to be located on the computer by default but I wonder if this solution would part work for others in a slightly different situation also. 

Hi Kenneth,

Did you manage to run the Strand7 API on Rhino 64-bit?

Also, how did you import the .cs file?

Many thanks,


Dear Andre,

Yes we got strand workingnwith 64bit gh but it required a workaround. The workaround was to use an externally played exe program which would activate strand7 after being prompted by grasshopper with the correct parameters etc. In grasshopper I used the command process.start(string [] parameters) to transfer our parameters as an array of stings to the exe program. The program was created in visual studio and written in c# so it is far easier to add libraries etc and allows you to work with strand 7 quite simply. 

I cannot remember the exact syntaxes of stuff but it's all quite basic and can find some great tutorials. If you need more help il send you my scripts. 

Regarding adding the extra dlls I described a solution to my problem above but it was a bit of luck so not sure if it will work if your situation is significantly different. 

Good luck 


Hi Kenneth,

Thanks for your reply! The parameters you passed in the array of strings were the API commands and content of variables?

I've been using the St7 API in Python but, in some situations, Rhino crashes for reasons I haven't been able to understand. Spawning a new process might help to avoid that.

Dear Andre,

The tool we developed in this feed was only concerned with using the St7 automesher and so the St7 commands were always the same and located in the exe. The parameters were the things like mesh size, mesh type etc. 

We developed another tool that was more robust a strand7 interface tool such that any command could be sent from rhino to strand but I am far less familiar with this one so I will ask my colleague to get into contact with you regarding that. 

If rhino is crashing that is concerning and suggests code instability. Did you program an error handler? (iErr) that was described in the sample codes? Additional to that I would build in stops - time outs and messages for debugging. Then you can see where it freezes and figure out why. 

I will contact my colleague now and get back to you asap. 

Kind regards







  • Add Photos
  • View All


  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service