Execute C# Code directly in Rhino


I am wondering if there is a way to compile and run C# code directly in Rhino.

I know that there’s a C# editor in Grasshopper to do this. But there’s no such an editor or plugin for Rhino.

I can afford to have my own Rhino plugin to do this work. I’ve looked into CSharpCompiler Class in .NET but don’t have a clear idea yet.

I am wondering if there is a RhinoCommon api for this, the similar like PythonScript Class but for C#?

Or there is another way to directly use .NET api to do it?

Any suggestions would be much appreciated.

Thanks ahead!

Yse, there is a RhinoCommon for .NET (C# & VB.NET), and yes, you can write a plugin which you install directly into Rhino (this is ho0w many commands are actually added to Rhino, “natively” so to speak).

There are examples of how you write a plugin (= a command plugin) for Rhino, using VS, on these pages (common API page):


// Rolf

With the way of working described below, it is possible to separate declaration and implementation of C# commands. The implementation assembly is read from byte stream, and can be reloaded when the command executes. That way it can always be rebuilt while Rhino is running, and the latest version is loaded as the command executes. We use this approach, and it saves a ton of time because you don’t have to restart Rhino each time the implementation of a command changes. We also use it for Grasshopper assemblies.


Thanks Rolf.

Sorry for not being clear. What I meant is to execute C# code dynamically. Just like RhinoPythonEditor in Rhino, but instead, a C# editor.

I was planning to have a RhinoPlugin to compile and run C# code. It doesn’t need to be a proper editor, but it should be able to execute the code…

Any thoughts on this?

Thanks Menno!

this looks very promising to build the tool that I want.

Will give you a feedback once I had the chance to try it out.