Search code examples
pythonpython-3.xmaya

Change Current Render Engine to V-Ray using Python in maya 2022


I'm just trying to change the current renderer in render settings to V-Ray in maya.

I followed this : Maya Python change current renderer in render setting But it's not working with V-Ray option

I also tried this :

import maya.cmds as cmds

# ensure plugins are loaded
cmds.loadPlugin("vrayformaya", quiet=True)
cmds.loadPlugin("vrayvolumegrid", quiet=True)

# auto load
cmds.pluginInfo("vrayformaya", edit=True, autoload=True)
cmds.pluginInfo("vrayvolumegrid", edit=True, autoload=True)

# edit attribs
cmds.setAttr("defaultRenderGlobals.currentRenderer", l=False)  
cmds.setAttr("defaultRenderGlobals.currentRenderer", "V-Ray", type="string")

# Recreate the render window to refresh them
if cmds.window("unifiedRenderGlobalsWindow", exists=True):
    cmds.deleteUI("unifiedRenderGlobalsWindow")
mel.eval("unifiedRenderGlobalsWindow")

And i don't know why, but this code works for 'arnold' but not for 'V-Ray', in this line

cmds.setAttr("defaultRenderGlobals.currentRenderer", "V-Ray", type="string") 

Thank you


Solution

  • Try to read the correct value when you manually switch to VRay:

    print(cmds.getAttr("defaultRenderGlobals.currentRenderer"))
    

    Then when you know the correct name, you can use it in your code:

    cmds.setAttr("defaultRenderGlobals.currentRenderer", "vray", type="string")