[rhinocommon] Getting the name or path of an opened non-3dm file

Hi Gerco, one alternative would be to parse the reversed command history text. If a file has been opened or imported successfully it is reported in the command history similar like this:

File "D:\Temp\FileName.obj" successfully read

I´ve hacked this together in python which seems to work, note that it reports the last opened file (eg. opened via drag & drop). If multiple files are opened without saving as 3dm, the title text remains at the one imported first.

import Rhino

def LastFileSuccessfullyRead():

    # get command history text
    ch_text = Rhino.RhinoApp.CommandHistoryWindowText
    if not ch_text: return None

    # no file yet
    file = None

    # command history text as line list
    lines = [line for line in (ch_text.split('\n'))]

    # reverse lines in text to search backwards
    lines.reverse()

    # find "File ..... successfully read" string
    for line in lines:
        a = line.find("File") 
        b = line.find("successfully read")
        if a > -1 and b > 5:
            file = line[a+6:b-2]
            break

    return file

if __name__=="__main__":
    file = LastFileSuccessfullyRead()
    if file: 
        print "Last imported file:", file
    else:
        print "Error getting last imported file"

it is a workaround :smile:

c.