Export selected objects using RhinoApp.RunScript()


I’m trying to export all the objects on a layer. In this case, to an OBJ file, but I’m not sure the destination file really matters. The goal is to make this totally non-interactive, so that no user input is needed.

This is what I’ve got so far, derived from some existing code that exports everything. ‘layername’ is a string passed in containing the name of the layer I want to get the objects from. ‘destfile’ is the fully-qualified name of the file to export the data to.

RhinoDoc doc = RhinoDoc.ActiveDoc;
Rhino.DocObjects.RhinoObject[] rhobjs = doc.Objects.FindByLayer(layername);
if (rhobjs != null && rhobjs.Length > 0)
   foreach (Rhino.DocObjects.RhinoObject obj in rhobjs)


   string RhinoCommand = @"_-ExportWithOrigin _SelAll _Enter _Enter " + "\"" + destfile + "\" _Enter _Enter _Enter";
   bool rhinoScriptResult = RhinoApp.RunScript(RhinoCommand, true);

‘_SelAll’ exports everything. How do I tell it to export only the selected objects?


Remove _SelAll. The foreach-loop already selects the objects. Instead I would add a RunScript that does SelNone before the foreach-loop.

Thanks Nathan.

I was able to use a plain Export instead, and just had to get the ‘Enters’ in the right places.
string RhinoCommand = @"_-Export " + "\"" + destfile + "\" _Enter _Enter";