Using Python to Batch-Generate Step Files and Other Outputs


I’m trying to use some Python code to batch-run a Grasshopper model. The Grasshopper model is encapsulated in a cluster, which accepts a few input paths & filenames and writes out a STEP file and a couple of text files (green box below). This seems to run fine. I’ve also written a Python code which reads another input file (red box). This input file is a list of paths on which to run the main model. The intention is that the Python code then runs the main model for each of these paths, generating output files for each.

This generates outputs for the last file in the series only. It appears that the cluster does not run until the Python script has completed, so the previous files are not processed. Is there a way of forcing the cluster to run for each of the other files too? I’ve tried using ExpireSolution(True), but this doesn’t work.

My Python code is as follows:

import Grasshopper as gh
import scriptcontext as sc

ghObjects = ghenv.Component.OnPingDocument().Objects

for obj in ghObjects:
if obj.NickName == “InputFilename”:
input = obj
elif obj.NickName == “OutputPath”:
output = obj
elif obj.NickName == “RunToggle”:
RunToggle = obj
elif obj.NickName == “BatchFilename”:
batch = obj
elif obj.NickName == “GenerateGeometry”:
GenerateGeometry = obj
if runNow:
lines = open(batch.UserText, “r”).read().splitlines()
for line in lines:
input.SetUserText(line + “/1_Initialisation/Parameters.txt”)
output.SetUserText(line + “/2_Geometry/”)

Thanks very much,