Button to Launch Script (with space in file path)

Hi,
I am trying to have a custom button that launches a grasshopper script. I’ve done this many times through the method below with success, but unfortunately in this case, the file path has a space in the string (“Example Path”), which then disrupts the macro as the space is seen as an execute command.

Is there anyway to run this macro so that the space isnt considered in the string? I tried replacing the space in the file path with \040 but this still seemed to execute the command.

Thanks,

_NoEcho
! -_RunPythonScript (
import os
import rhinoscriptsyntax as rs
homepath = os.path.expanduser(’~’)
scriptspath = ‘\Documents\Example Path\example.gh’

file_path = homepath + scriptspath
command = "-_Grasshopper _Document _Open "+file_path
rs.Command(command )
)

maybe this is helpful

Thanks Inno. This worked perfectly. Putting the file path in double quotes makes it take the full file path without the spaces executing the command.

To amend the macro above, I have just done the following:

_NoEcho
! -_RunPythonScript (
import os
import rhinoscriptsyntax as rs
homepath = os.path.expanduser(’~’)
scriptspath = ‘\Documents\Example Path\example.gh’

file_path = ‘"’+homepath + scriptspath+’"’
command = "-_Grasshopper _Document _Open "+file_path
rs.Command(command )
)

2 Likes