Skip to content

Instantly share code, notes, and snippets.

@StepMaher StepMaher/
Last active Mar 28, 2016

What would you like to do?
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
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
You can’t perform that action at this time.