Export file from Python command


I’m writing my first Rhino command! I’d like to be able to run a command, select some objects, and have them open directly in Sketch for Mac. I’ve got every aspect of this figured out and most of the code written, but I can’t for the life of me figure out how to script the file export! I’d like to export the selected objects (I scripted selecting them) as an Adobe Illustrator file, which I’ll then convert to SVG for import into Sketch. How do I write a one-line export command, one that I can put in the line that reads rs.Command("! _-Export") so that the selected objects will be exported as a .ai file with no pause to input parameters each time? Or is calling rs.Command the wrong way to go about this?

Any help would be much appreciated!!

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

__commandname__ = "Diagram"

def RunCommand( is_interactive ):
    obj = rs.GetObjects(filter=4)
    if obj:
        print "Exporting..."
        rs.Command("! _-Export")
        print "Error: no objects selected"

Thanks so much,

Hi Sam,

I’m not familiar with the mac side, but on the windows side you can extend the -Export with additional strings to complete the command. You can regard everything passed to rs.Command() as a macro.
To export an illustrator file this should/could work:

rs.Command('! _-Export "fileforillustrator.ai" _Enter')

Note I encapsulated the command string in single quotes to be able to use double quotes around the filename to not cause error when the filename contains spaces.


  • Willem
1 Like

@Willem ,

Thank you for your help! I think I’m closer now… Rhino prints Directory "(null)" does not exist and I’m assuming there’s another macro option for the directory to save to. Is there a standard place to get all macro options for a command? If not, do you know how I could set the save location to a known directory?

Thanks again,

Never mind, I figured it out! I just needed to specify the entire file path to export the file to, rather than just the filename.