Assign render engine through Python script - Rhino V-Ray

Hello,

I’d like to let a user choose a render engine (CPU, CUDA or RTX) through a Python script, with an Eto window. It is part of a batch export script of VRayScenes.
I wrote the UI part with Eto with no problem (a RadioButtonList switching between the engines). But I’m not succeeding in linking the render engine to the buttons, I can’t call the engine.
I’m trying to use this: (found here)


import rhVRay as vray

cudaDevices = vray.GetDeviceList(vray.RenderEngines.RE_CUDA)
enabled = cudaDevices[0].UseForRendering

or this:


import rhVRay as vray

cudaDevices = vray.GetDeviceList(vray.RenderEngines.RE_CUDA)
name = cudaDevices[0].Name

I get the following error : Message: ‘module’ object has no attribute ‘GetDeviceList’.
Same thing to define the level of render quality : there are 6 levels in V-Ray UI (Low’, ‘Low+’, ‘Medium’, ‘Medium+’, ‘High’, ‘High+’) but I don’t find how to access them.

I can’t find anything on forums, any help will be appreciated ! (I started not long ago scripting in Rhino so I don’t have a global vision of how it fully works)

I work​ on:
Rhino 6 SR35
V-Ray 6 5.20.05
Windows 11

Thank you !

Ok, the issue was the version of V-Ray, the script works after the upgrade. My very bad !
Guessing the command to set the render engine (to CUDA for example) is:


import rhVRay as vray

vray.RenderEngines.RE_CUDA

but not sure if it is really assigning the render engine.

I know this exists:


vray.Render(renderEngine, renderMode, -1)

But I don’t want to render, I want to export vr_scenes, that’s why I’d like to set the render engine, before exporting.

I still can’t find how to access though to the render quality. I understood through this post that it may be taken into account by the UI development team soon. Fingers crossed !

Hello matferbourgeat_groupe​,
Thank you for writing us!

1. Choosing a Render Engine is not in our documentation yet, but here is one proposal to do it.
For setting the Render Engine to CUDA for example, you can use this Rhino Python 2 script:

import rhVRay as vray

with vray.Scene.Transaction():
    vray.Scene.SettingsOptions.render_mode=4

​Here is a list of render modes:

enum RenderMode {
 RENDER_MODE_PRODUCTION = -1,
 RENDER_MODE_INTERACTIVE = 0,
 RENDER_MODE_INTERACTIVE_CUDA = 4,
 RENDER_MODE_INTERACTIVE_OPTIX = 7,
 RENDER_MODE_PRODUCTION_CUDA = 104,
 RENDER_MODE_PRODUCTION_OPTIX = 107,
};

After running the script, the change will be applied and visible in the V-Ray Asset Editor > Settings > Render.

2. Here is an example of how to set the CUDA devices using GetDeviceList and SetDeviceList methods. (It is also similar to changing the RTX devices.) Short video here.

import System
import rhVRay as vray

def listme(devices):
 for device in devices:
  name = device.Name
  use = device.UseForRendering

  print("device name:" + name)
  print("use device:" + str(use))

device_new=vray.RenderEngines.RE_CUDA
cudaDevices = vray.GetDeviceList(device_new)
listme(cudaDevices)

vray.SetDeviceList(device_new, [0]) #set the devices - 0=CPU, 1=GPU CUDA...
cudaDevices = vray.GetDeviceList(device_new)
listme(cudaDevices)
```​
As a result, the first two "use device" lines show the existing device settings:
![existing.png|978x289](upload://7l18Cm3P1ydxz6pj4FXzAmDP54M.png)
The last two "use device" lines show the new device settings:
![new_set_devices.png|976x284](upload://sZnVaVSVdEyWj3jnOnpkpCx1WJy.png)

3\. About the script for the **Render Quality** \- we will share here, as soon as there is some news.

Kind regards,
Ivelina
​
![new_set_devices.png|976x284](upload://sZnVaVSVdEyWj3jnOnpkpCx1WJy.png)
![existing.png|978x289](upload://7l18Cm3P1ydxz6pj4FXzAmDP54M.png)

Thank you so much @ivelina_mincheva !
Everything’s clear and perfectly operating.
Can’t wait for the news about Render quality scripting.

Best regards,

J.