Get filname from import

Hello, if i import a STL file, is it possible to get the filename somehow?
writing my own importer is also an option but i would rather not since i would like to use the normal workflow of importing files.


Rhino does not retain the file name of an imported file. So, there is no way of retrieving it. The way to handle this in a script is to script the Import command yourself. In doing this, you’d have the file name.

Hi Elvind,

You could script something like this too:

Sub Runfile
Dim strFilename,item

strFilename = Rhino.OpenFileName
If Not IsNull(strFilename) Then
Rhino.command “import” & " " & strFilename & CStr(item)
End If
End Sub

If needed you could add the copy to clipboard method to copy the file name etc. and or add save as then the imported file name to save the imported file as a .3dm not sure what you want to do with the name after importing.


ok Dale, i will look into doing it myself :wink:

Thanks! i am a python man myself, but your vb looks pretty easy and nice, i will give it a go :wink:

i belive Rhino.FileIO import FileWriteOptions, FileReadOptions is the way to go, please correct me if i am going the wrong way now :wink:

When opening or importing files, it is best to script Rhino’s Open or Import command using rs.Command.

ok Dale, thanks for that info. But it feels like cheating :wink: but whatever floats the boat right!

I will post my fileImporter method when it is done.

I will search for it, but in case this forum is faster, how does one send the enter/return char with the rs.Command? it will be used later in my python script to export the selected mesh to a .STL file in the same dir as i get with the OpenFileName command

If you use rs.Command, the command you are calling will run like a normal Rhino command. If that command needs an Enter to confirm a selection or something like that, it will stop and wait for it like usual - so you don’t need to do anything special. Otherwise, if you want to jump over it, you can simply script the _Enter inside the rs.Command string after the command, in the same way as you might put an _Enter in a Rhino command macro.

HTH, --Mitch

Thanks, i did find this information on the forum, never seen this before, i like the idea of sending the commands inside the string variable. :slight_smile:

Thanks for all assistance, here is my FileImport and FileExport in case someone wants to do this in python later

strFilename = ""

def FileImport():
    global strFilename
    strFilename = rs.OpenFileName(folder="c:\\temp")
    if strFilename:
        importCommand = "-_Import " + strFilename + " -_Enter"

def FileExport():
    global strFilename
    if strFilename == "":
        commandString = "-_Export"
        commandString = "-_Export " + strFilename +"-Corrected.stl " + "-_Enter " +"-_Enter"

if __name__=="__main__":
    msgImport = rs.MessageBox("Would you like to import a file?", 4 + 32)
    if msgImport == 6:
    SomeCommand() #import a new object or use the selected one
    msgExport = rs.MessageBox("Would you like to Export the corrected Last?",4 + 32)
    if msgExport == 6:
    elif msgExport == 7:
        print("No Export")
1 Like