Retrieve filename of imported file

Hi,

If a user had opened a none Rhino file (eg a stp file)
The filename is displayed in the window title:
image
How would I retrieve the info on the imported file.
IS that available through RhinoCommon or should I just grab that title somehow ( if so does anybody know how)

Thanks
-Willem

hi Willem, is this what you are looking for?https://developer.rhino3d.com/api/RhinoCommon/html/P_Rhino_RhinoDoc_Name.htm

Rhino.RhinoDoc.ActiveDoc.Name

The following works, if the file has been saved with a name (a new non-saved file will return a null string):

RhinoApp.WriteLine( RhinoDocument.Path );

// Rolf

Thanks for the suggestions,

The problem is like Rolf points out:

So a non Rhino file that has been opened (imported upon opening) does not have a retrievable name like displayed in the window title.

Thanks
-Willem

Hi @Willem, one way would be to grab the required info from the command line after the file has been opened (or imported). A similar question has been answered here.

Note that Rhino 6 seems to have a different string in the command line than the one shown in the example linked above.

Another way would be to get the title from the process id. Below was tested with Rhino 6, with only one open instance:

import System
from System.Diagnostics import Process

try: 
    proc = Process.GetCurrentProcess()
    title = Process.GetProcessById(proc.Id).MainWindowTitle
    text = title.Split()[0]
except:
    text = None
    
print text

_
c.

2 Likes

Hi Clement,

Your script did not work, after some checking I got a working setup:
Yours did not get the title for some reason. I found I can grab the title directly from the proc in your script

    import System
    
    try: 
        title = System.Diagnostics.Process.GetCurrentProcess().MainWindowTitle
        text = title.Split()[0]
    except:
        text = None
        
    print text

Thanks Willem

Hi @Willem, hm, just checked and above first snippet seems to work over here. But your change is also working well. It should be noted that for an unsaved doc without having opened a non 3dm file, the title text returned is just “Rhinoceros”.

_
c.

1 Like