How do I make Python code wait for V-Ray to finish rendering?

I’m trying to render about a thousand objects (all named uniquely) by copying them to a render stage window, rendering, then deleting it and repeating with the next object in the list. Everything works fine, but I can’t figure out how to make the code wait for V-Ray to finish. Looked for VRay API online, couldn’t find it. My workaround was to have a prompt for the user to hit Enter when V-Ray finished writing the file.

The things I tried:

time.sleep(30) : tried to make it wait 30 seconds for Vray before saving, but no, this suspends ALL processing. Looking in windows task manager, I can see that it’s the Rhino64bit process that eats up all proc time while rendering, don’t know if I can isolate the subprocess and keep it going without the API. The system waits 30 seconds, but the renderer DOES NOT keep going in this time.

while loop comparing file timestamps : again, the code takes over the proc and doesn’t even allow the renderer to continue, and eventually freezes Rhino.

rs.Command(“SaveRenderWindowAs”) : is there a way to make this wait for V-Ray to finish? I get those pop-ups from vray: “Please wait for the renderer to finish” when I use this, and a bunch of saved files of the render cache in progress.

Here’s the section of my code that outputs it (with failed attempts in comments).

    rs.Command("!_Render", echo=False)
#    while ((newfiletime <= oldfiletime) and (newfiletime < (time.time() - 5 ))):
#          newfiletime = os.path.getmtime("vrayoutputfile.png")
#          print("New file time = " + time.ctime(newfiletime))
#          print("current time = " + time.ctime())
#          print(".")
# foobar = rs.GetString("Hit Enter when rendering complete") # fallback method
# time.sleep(30) # this suspends execution don't use it!
    rs.Command("-_SaveRenderWindowAs "+os.path.join(filepath, fileseed + filenum + "_RDR.png"), echo=False)
#    shutil.copyfile("vrayoutputfile.png",
#                    os.path.join(filepath, fileseed + filenum + "_RDR.png"))

The shutil.copyfile command copies the outputfile as defined in the V-Ray options under “output,” which was how I was doing it previously, having to hit enter or space after visually (i.e. using my eyeballs) checking to see if the render window was finished. What a hassle! I want to automate this process completely…

Thanks in advance for any ideas you people may have.

1 Like

You can check option in Vray options to batch render. This makes it so all rhino functions wait until rendering is complete so your commands render and then saverenderwindow will work as you expect.

1 Like


(thank you) :wink:

And there’s a way to programatically ensure that this switch is turned on. It was discussed recently in V-Ray’s forum.