Rhino Command Export in C#


I have a script written in C# that creates, bakes and selects baked geometry.

I am trying to add some lines to export selected geometry into the dxf file. How to do it?

Hi @aleksanderdynarek,

Select the newly baked geometry and then script the Export command using RhinoApp.RunScript.

Here is the plug-in command equivalent of what you’ll want to do:


– Dale

1 Like


How exactly should I do it in this code?

      Rhino.DocObjects.Tables.ObjectTable ot = Rhino.RhinoDoc.ActiveDoc.Objects;
      ot.AddLine(new Point3d(0, 0, 0), new Point3d(1, 1, 1));
      //get guid of the most recent object
      Guid id = ot.ElementAt(0).Id;

      //deletes this object
      //if(z) ot.Delete(id, true);

Be aware that ActiveDoc may return a null reference under certain circumstances. You should probably check for null before using it:

var doc = Rhino.RhinoDoc.ActiveDoc;
if (doc == null) return;

if (x)
  var lineId = doc.Objects.AddLine(new Point3d(0,0,0), new Point3d(1,1,1));
RhinoApp.RunScript("-_ExportCommandHere", true);

I think that the problem is, that I do not now exactly how to write RunScript command :slight_smile: I mean, full one, with directory, file name, ENTER, etc. Could you help please?

It’s whatever you would type into the Rhino command line to make it work. It usually takes me a while to figure out all the exact options and _Enters required to make it work.

The basic approach will be running the -_Export command (with the hyphen and the underscore; the hyphen suppresses dialog boxes and the underscore forces the English command name). Then you must include the filename with the correct extension. You’ll want to encase it in double quotes in case it contains any spaces. Then it seems you can either select a scheme, or use the default.

string command = "-_Export \"C:\Users\David Rutten\Desktop\export.dxf\" _Enter";

thanks, but unfortunately it show some error :frowning:

var doc = Rhino.RhinoDoc.ActiveDoc;
if (doc == null) return;

if (x)
  var lineId = doc.Objects.AddLine(new Point3d(0, 0, 0), new Point3d(1, 1, 1));

string command = "-_Export \"D:\Profile\adminek\Desktop\export.dxf\" _Enter";
RhinoApp.RunScript(command, true)


  1. Error (CS1009): Nierozpoznana sekwencja specjalna (line 82)
    (its in Polish, in English it would be something like “unidentified special sequence”)
    line 82 is the line with string command

I was googling around for a possibility to in a definition automatically bake a geometry - stop and let me execute regular rhino fillets (or any other regular command) - then automagically pick this new geometry and continue in grasshopper.
Would this be possible?

Yeah my bad, backslashes are escape chars in C#, so it should have been:

string command = "-_Export \"C:\\Users\\David Rutten\\Desktop\\export.dxf\" _Enter";

works :slight_smile: so cool, thanks!