Python rs open file command

Trying to open a file with a button but don’t really understand which way wrote the information into the command line.
here is my python work :


open-doc-command.gh (2.4 KB)

I find myself that I must wrote a double \ → \ but still can’t directly acces to the file…

Hello,
This just returns a string giving the path to the file - it does not open it. You could maybe use rs.Command() afterwards to script the -_Open command to load the file …?

https://developer.rhino3d.com/api/RhinoScriptSyntax/#userinterface-OpenFileName

Put a r in front of the string and then no need for double backsplashes. r stands for raw string in Python.
r’your string with single backslash separators’

2 Likes

Thanks, so it show that this is not what I’am looking formaybe… :

modifying the code I get that :

but it still left some return or enter or OK command to openthe file :

any other idea or command that I can use ? THX !

You’re welcome!

Like this:

HTH

If you’re trying to open a Grasshopper file from a GHPython component (the methods suggested in this thread are for opening Rhino files), have a look at this old thread:

Additionally, here’s how to access the solution suggested by David in that same thread:

1 Like

sorry I didn’t understand it really well the first time I read it !

So I decided to wrote it that way :

this is my result :

import rhinoscriptsyntax as rs

if x == True :
path = ‘“H:\0_ACAD\10_DEVELOPPEMENT\LM_ARB_Firefly\Firefly.gh”’
rs.DocumentModified(False)
rs.Command(‘_-Open {} _Enter’.format(path))

thank you very much all of you !!

I did it 3 different ways and all have the same trouble…
It kind of “freeze” grasshopper. It open the file, but then I can’t do anything but zoom in or zoom out in Grasshopper, noting else. In rhino everything is OK, I try to close and open the grasshopper file again but it do not change anything. If I shut Rhino and open everything again, everything get back to normal working…
see it there :
file-launcher.gh (3.8 KB)

This happens when you execute this type of script using a Button. You can use a Boolean Toggle instead, or alternatively a Value List (set to Value Cycle with just a list of two Trues in there).

thanks it helps !

Thanks! Works fine, just has to be on an instance.

import Grasshopper as gh
gh_scriptinterface = gh.Plugin.GH_RhinoScriptInterface()
gh_scriptinterface.OpenDocument(r"path\to\file")

1 Like