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?
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).
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.
a = os.path.dirname(os.path.abspath(path))
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”.