VRay Render with Python Crashes Rhino

Currently trying to render a bunch of objects using Python to automate the process. However, I’ve hit a brick wall trying to convert a running script into a Rhino command using every procedure available to create commands from Python scripts, namely:

  • Toolbar Button
  • RhinoScript Plugin
  • RhinoScriptCompiler

Getting the exact same results, the script seems to work before the actual VRay render command, then it hangs making rhino unresponsive which requires a forced shutdown.

The script is reasonably extensive, it asks for output folder and image size, etc… But I have isolated the line that crashes Rhino, here it is:

vray.Render(0,0,-1)

What makes this problem a little hard to understand is the fact that running the script using Rhino Python plugin for VS Code and CodeListener plugin for rhino works great, this is the way I test my scripts then when attempting to convert this particular script into a Rhino Command using any of the methods mentioned above, the script bombs.

Worth mentioning that all other scripts converted into plugins, commands or toolbar buttons, etc… work just fine, I’ve converted quite a few using this method. When it comes to the synchronous VRay render command, it fails.

Any pointers as to where I should be looking next would be greatly appreciated as I have spent the last few days tearing whatever little hair I have left over this issue.

Cheers

Hi,

It “hangs”, because it is synchronous. It simply waits fir the render to finish. If, for some reason, a dialog window need to show, it will hang for ever. Thus is because python scriots are executed on the main gui thread.
There are more reasons if course, but gui lock is most common.

Make sure V-Ray can start rendering the model from toolbar/menu. If it starts without any dialogs poppinv up, it is not a gui lock

After further testing the script which runs fine when sourced directly form a .py file seem to have all sorts of weird problems when run as a Python Command (as described here) or inside a plugin, errors like file.exr not valid file name or not valid folder, etc… These are not errors in the script but according to your answer may be due to the fact that the code is not run inside the main UI thread.

The problem has been solved by sourcing the Python script directly from a Python source file as described here.