Rhino Command Export in C#


(Aleksanderdynarek) #1


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?

(Dale Fugier) #2

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

(Aleksanderdynarek) #3


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);

(David Rutten) #4

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);

(Aleksanderdynarek) #5

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?

(David Rutten) #6

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";

(Aleksanderdynarek) #7

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

(Pelle) #8

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?

(David Rutten) #9

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";

(Aleksanderdynarek) #10

works :slight_smile: so cool, thanks!