i want to automate my application in rhino, so i’m working in batch mode. I was able to run rhino and grasshopper in batch mode. Hovewer, rhino pops up, when I run the following code in cmd:
I saw same questions in forum, but nobody solved this problem in python (at least I didn’t see it). Is there a way running rhino 7 without popping up. Some other softwares use commands like ‘-batch’. Is there also such a command in rhino?
Thank you for your response Wim and AIW. I tried rhinoinside. However, I got this error. Do you have any idea, why did I get this error and how can I solve it?
Little translate to english: “the given assembly name or the code basis is unvalid”
If I try to launch python code in rhino command, I get the same error message. However, it works, when I launch the code in second time. I need to run this python code from cmd.exe with the following code:
“C:/Program Files/Rhino 7/System/Rhino.exe” /nosplash /runscript=" _-RunPythonScript GrasshopperRhinoInterfaceScript.py"
Python code:
import rhinoinside
rhinoinside.load()
import os
import System
import Rhino
import clr
clr.AddReferenceByName(“Grasshopper”)
import Grasshopper
from Rhino import RhinoApp, RhinoDoc
from Rhino.Geometry import *
import rhinoscript as rs
import scriptcontext
def DocumentModified(modified=None):
“”“Returns or sets the document’s modified flag. This flag indicates whether
or not any changes to the current document have been made. NOTE: setting the
document modified flag to False will prevent the “Do you want to save this
file…” from displaying when you close Rhino.
Parameters:
modified [optional] = the modified state, either True or False
Returns:
if no modified state is specified, the current modified state
if a modified state is specified, the previous modified state
“””
scriptcontext.doc=Rhino.RhinoDoc.ActiveDoc
oldstate = scriptcontext.doc.Modified
if modified is not None and modified!=oldstate:
scriptcontext.doc.Modified = modified
return oldstate
#Required to set current working directory of rhino that grasshopper can see the path
cmd="-SetWorkingFolder “+”"“+os.getcwd()+”""
rs.application.Command(cmd)#Doesn’t correctly pass working dir to grasshopper
rs.application.Command("-SaveAs " + “delete.3dm”)#this operation does,…somehow
My gh script takes some parameter from .txt file. The parameters are numbers and text. Then, it creates geometries with given parameters and export them as .x_t or .igs file.
Everything works very well, when I execute rhino from outside. However, rhino pops up, when I execute the script. I only prevent this popping up and want to launch rhino in background.
You definitely don’t need this for the way you are starting Rhino. That is for running Rhino inside of CPython and that is not what is being done here.
You should be able to do what you are trying to do with our external access technique. Here’s a post where something similar was done
all of codes are in VBA. Is it also possible to do that in python? I mean, actually I use HEEDS software for automation and connection of rhino with some other software. But, what HEEDS does only creating the following code and execute it in CMD: “C:/Program Files/Rhino 7/System/Rhino.exe” /nosplash /runscript=" _-RunPythonScript GrasshopperRhinoInterfaceScript.py"
Therefore, the external access to Rhino should be done with using GrasshopperRhinoInterfaceScript in python. Do you have any example for that?
HEEDS would launch a vbs file with the script to launch and run Rhino. In the script you would call RunScript "_-RuntPythonScript GrasshopperRhinoInterfaceScript.py"