Grasshopper

algorithmic modeling for Rhino

Hi,
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
Mark

Views: 5874

Replies to This Discussion

Hi Mark,

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.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Hi Mark,

for a simple implementation of FilePath as David mentions, see this example.
It would be, in short:

owner.OnPingDocument().FilePath

Thanks,

- Giulio
_______________
giulio@mcneel.com

Attachments:

That's great, thanks a lot.

Mark

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.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Giulio,

What is the python equivalent of:

owner.OnPingDocument().FilePath

 

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.

 

thanks

 

Jonathan

 

file_name = ghenv.Component.OnPingDocument().FilePath

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service