Skip to content

Instantly share code, notes, and snippets.

@StepMaher
Last active March 28, 2016 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StepMaher/d85b59a7c38108dec3c1 to your computer and use it in GitHub Desktop.
Save StepMaher/d85b59a7c38108dec3c1 to your computer and use it in GitHub Desktop.
"""
Finds a file in the same directory as the Grasshopper file.
Inputs: Name: File name and extiestion to grab.
Outputs: Path: Full file path.
"""
# Name component
ghenv.Component.Name = "Relative File Path"
ghenv.Component.NickName = "RelFilePath"
# Import libraries
import os
import Grasshopper as gh
# Get GH file path
gh_path = ghdoc.Path
dir = os.path.dirname(os.path.realpath(gh_path))
# Join GH file path and file name
path = os.path.join(dir, Name)
# Test if that file exists
if os.path.isfile(path) == True:
Path = path # Declare output param
else:
msg = "File does not exist."
ghenv.Component.AddRuntimeMessage(gh.Kernel.GH_RuntimeMessageLevel.Warning, msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment