Last active
April 13, 2022 07:01
-
-
Save thekaushikls/36225fc7c268cfb3f9537ca5ad3f285e to your computer and use it in GitHub Desktop.
open gh file on startup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
Usage: gh_autoloaded.py | |
This script attempts to load a grasshopper(.gh) file if it shares the same name as the current | |
rhino(.3dm)file, and is placed in the same directory. | |
Note: | |
This script uses the RhinoCommon library to locate the current ActiveDocument. | |
""" | |
# - - - - - - - - IMPORTS | |
import os | |
import Rhino | |
# - - - - - - - - FUNCTION | |
def try_load_grasshopper(): | |
file_3dm = Rhino.RhinoDoc.ActiveDoc.Path; | |
if file_3dm is not None: | |
file_gh = file_3dm.replace('3dm', 'gh') | |
if os.path.exists(file_gh) and os.path.isfile(file_gh): | |
Rhino.RhinoApp.WriteLine('\nFile Found: {}\n'.format(file_gh)) | |
cmd = '_-Grasshopper Document Open {} _Enter'.format(file_gh) | |
Rhino.RhinoApp.RunScript(cmd, False) | |
return True | |
Rhino.RhinoApp.WriteLine('\nNo File Found.\n') | |
Rhino.RhinoApp.WriteLine('\nGrasshopper was not loaded: Current Rhino file is not saved.\n') | |
return False | |
# - - - - - - - - RUN SCRIPT | |
def Run(): | |
try_load_grasshopper() | |
if __name__ == "__main__": | |
Run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment