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

**URL:** <https://discourse.mcneel.com/t/rhinocommon-getting-the-name-or-path-of-an-opened-non-3dm-file/7838>\
**Category:** Rhino Developer\
**Created:** [April 25, 2014, 8:18am UTC](https://discourse.mcneel.com/t/rhinocommon-getting-the-name-or-path-of-an-opened-non-3dm-file/7838 "2014-04-25T08:18:56Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![clement](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/clement/32/772979_2.png) [@clement](https://discourse.mcneel.com/u/clement)\
**Post date:** [April 27, 2014, 4:18pm UTC](https://discourse.mcneel.com/t/rhinocommon-getting-the-name-or-path-of-an-opened-non-3dm-file/7838/5 "2014-04-27T16:18:07Z")

</div>

> [@gercodejager](#):
>
> Anyone a suggestion how to get the name of a non-3dm file after it was opened?

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.

```Python
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 😄

- 

c.

---

_[View the full topic](https://discourse.mcneel.com/t/rhinocommon-getting-the-name-or-path-of-an-opened-non-3dm-file/7838)._
