Get file path of currently open .3dm

I’m trying to have a component output the filepath of the currently open Rhino file in as painless of a way as possible.
I’ve tried rs.DocumentPath() in python but have found that it doesn’t update when a new file is opened or when the whole definition is recomputed.
System.IO.Path.GetDirectoryName(RhinoDocument.Path); in C# works, but the definition has to be recomputed and I’m trying to keep it super simple for my coworkers who don’t use Grasshopper much.

Is there a way to get the current file path that will always be accurate without having to recompute?

rhino path.gh (5.4 KB)

1 Like

I think this is what you’re looking for:

Rhino.RhinoDoc.ActiveDoc.Path

2 Likes

Short of hooking up some type of event listener to, (begin open doc/end open doc…or something), I don’t know how to have the component “auto fresh” when a new file is opened.
Easiest way might be to just hook a button component to a ghpython component, (using the path method that ivelin posted).

2 Likes

Ahh that helps a lot. It will be used in HumanUI so having a listener is no problem at all. This is working at the moment, I’m unsure why the button refreshes the path even though x isn’t defined in the script. But it works regardless.

path =Rhino.RhinoDoc.ActiveDoc.Path

a = os.path.dirname(os.path.abspath(path))

image

i use the button “trick” all the time. In this type of case, it doesn’t need to be declared in the code. The component just sees that something happened on one of the inputs, (button clicked), and the component “refreshes”.

x is defined as an input, even though you don’t see it, and everytime it changes (i.e. the button is clicked) it refreshes (updates/expires) the ghpython component.

You can see it better if you switch ghpython component into SDK mode.

That’s super useful to know, thank you!

1 Like

Just remembered, you can see “x” is defined as an object by looking into the globals dictionary: