Bug on .Bat to open rhino and a specific .gh file

So, I’m trying to write a .bat file that will open automatically rhino and a grasshopper simultaneously, the context is that I have a script that uses 6 different .3dm and 6 different .gh, but that is not important for the issue.

The issue is that when I run the .bat File, this problem appears.

It looks like it is not running the whole script (seen on the background), just the opening parenthesis.

To see bug just downloaod, unzip and put the file in your C:, then proceed to double click on the .bat, to see that it is not working.

BatScript.zip (4.4 KB)

What is interesting is that if I just copy and paste the following script in the command line, it does work! I don’t know why rhino command jus executes the opening parenthesis when done from the .bat file.

! _-RunScript (
Set GH = Rhino.GetPlugInObject(“Grasshopper”)
Call GH.OpenDocument(“C:\BatScript\PlaceHolderFile.gh”)
)

I have already searched on the forums and haven’t found much information on the topic, the best reference I got is this
( Running Scripts (rhino3d.com)
But it really talks about generating scripts, not running them from a .bat

Thanks in advance for any guidance that anyone can offer!

I could be wrong, but it looks like you may need to escape your quotes that are within the script.

So for each " within the script replace them with “”

FYI: Discourse is messing with my two double quotes, just make sure each 1 " is replaced with 2 "

1 Like

Thanks for replying, but it doesn’t seem to be the issue, since all that is executed in rhino is the _-Runscript and the opening bracket. It is wierd.

Still stuck on this, any input would be greatly appreciated :slight_smile:

parallel computation - run iterations on multiple computers? - Grasshopper (grasshopper3d.com)

Seems like this thread gives the long-awaited solution for the moment! Will update if anything.

Hi @Frusciante, i tried some similar process and have the same issue.
Hope someone can help.

1 Like

I’m going to spend some time on this in the morning. I had some progress, but need some more time.

If nothing else I should be able to narrow down the problem for McNeel to fix if needed.

1 Like

Runscript Doesn’t appear to work as you guys need, at least not in Rhino 7.

Here are some other posts which may get you where you need to go, they are just feeding commands to the command prompt rather than trying to use Rhino Script, that may work for you:

1 Like

I think your comment way back at the beginning was correct:

This batch file seems to have a number of syntax problems:

@echo off

cd\
cd Program Files\Rhino 7\System
Rhino.exe /nosplash /runscript="! _-RunScript (
Set GH = Rhino.GetPlugInObject("Grasshopper") 
Call GH.OpenDocument("C:\BatScript\PlaceHolderFile.gh")
)"

including nested double quotes, nested parentheses, and line breaks in the middle.

It might be possible to escape all of that if this is really a one-off.

The better solution by far seems to be rethinking the approach.

As a dev, for my own use I’d be thinking of something like a plugin which has a single command that’s easy to include in the command line.

Because this doesn’t appear to be a completely automatic background process (all it does is open some things) a one or two key macro is also an option, possibly using the batch files to shuffle which initial file is loaded.

It may circle around to “Hey @Frusciante , what’s the actual workflow you’re trying to achieve?”

2 Likes

I found how to solve the issue. This is the code I made, where I just get the newest Rhino file in the first loop and the newest grasshopper file in the second loop, then the syntax is a little different. You guys really helped me a lot, with some additional resources from the McNeel Documentation, which I didn’t save.

Here is my final code.

@echo off
setlocal enabledelayedexpansion

set "rhfileExtension=.3dm"
set "ghfileExtension=.gh"


cd..
set "RootDir=%cd%"


set "RHdir=%RootDir%\RH"
for /f "delims=" %%a in ('dir /b /o-d /a-d "%RHdir%\*%rhfileExtension%"') do (
	set "RHfile=%%a"
	GOTO FoundFileA
)
:FoundFileA


set "GHdir=%RootDir%\GH"
for /f "delims=" %%a in ('dir /b /o-d /a-d "%GHdir%\*%ghfileExtension%"') do (
	set "GHfile=%%a"
	GOTO FoundFileB
)
:FoundFileB


cd %GHdir%
start "" "C:\Program Files\Rhino 7\System\Rhino.exe" /nosplash /runscript="-Grasshopper Document Open %GHfile% _Enter -Open %RHdir%\%rhfile%

exit
1 Like