I’m trying to open a GrassHopper definition via a menu button, and via an Alias/PythonScript, and in all cases it does open GrassHopper, but but not the “hard coded” GrassHopper definition file. Why not?
Python script
import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
def RunGHDef():
Grasshopper = Rhino.RhinoApp.GetPlugInObject("Grasshopper")
if not Grasshopper: return False
Grasshopper.DisableSolver()
filePath = "D:\gh\my_grasshopper_file.gh"
Grasshopper.OpenDocument(chr(34) + filePath + chr(34))
Grasshopper.ShowEditor()
if __name__=="__main__":
RunGHDef()
From a Menu button I try the following, but same there, GrassHopper starts with an empty canvas, but the GH definition files does not open, although this time the file dialog opens, displaying the last opened folder. But, when I select the gh file file (using the open dialog) it still doesn’t open the file :
_GrassHopperOpen "D:\gh\my_grasshopper_file.gh"
The following is displayed on the command line after selecting a file to open:
About a year ago, I did a little test to try to use GH as a scripting tool …
Here is the script I used.
As far as I remember, it was able to open the GH definition …
I tried your script, but unfortunately it still doesn work. I get the exact same result.
There seems to be a flaw in GrassHopper’s API. For example, look at the resulting message from attempting to open a gh definition (there’s suddenly a \tab character in the file path):
Unable to load D: mp\with_underscores.gh
I get the same result message from the two paths in the code below (testing if underscores would play a role in this, but no go.
I have tried with paths containing underscores, spaces, numbers, as well as paths entirely without any such characters, but same thing - no go:
import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
def RunGHDef():
Gh = Rhino.RhinoApp.GetPlugInObject( 'Grasshopper' )
if not Gh:
return
Gh.LoadEditor()
Gh.CloseAllDocuments()
Gh.ShowEditor()
defn = "D:\tmp\with_underscores.gh"
#defn = "D:\tmp\withoutunderscores.gh"
ok = Gh.OpenDocument( "D:\tmp\with_underscores.gh" )
if not ok:
print( 'Unable to load ' + defn )
return