algorithmic modeling for Rhino
I want to create a grasshopper VB component that outputs the directory in which the active grasshopper file is saved. In Excel VBA it would be ActiveWorkbook.path but I can't find the GH equivalent, please help!
Thanks in advance
a grasshopper document might not have a filepath yet if it hasn't been saved. Or if it is a nested document (such as a cluster) within another document. When a document is loaded from a file, you can get the file location using the FilePath property. You can also use IsFilePathDefined to check whether or not the file path is defined. Hey ho.
Much trickier is to detect when it changes. When someone uses SaveAs, the file path will be different. There is no event associated with file path changes, so you'll need to detect this some other way. You could handle the ModifiedChanged event, but that will only work for a subset of cases.
for a simple implementation of FilePath as David mentions, see this example.
It would be, in short:
That's great, thanks a lot.
I just added a FilePathChanged event to the GH_Document, so in future releases you can be informed whenever the FilePath property gets a new value.
What is the python equivalent of:
I'm trying to find the directory of grasshopper .gh file from within a python component in order to have a relative path to another .py file.
file_name = ghenv.Component.OnPingDocument().FilePath