Can't get Maya to use harware rendering with Python

Can't get Maya to use harware rendering with Python

andy.lathamCJTQT
Contributor Contributor
846 Views
1 Reply
Message 1 of 2

Can't get Maya to use harware rendering with Python

andy.lathamCJTQT
Contributor
Contributor

Hi! I'm trying to get a hardware 2.0 render happening via Python, but I can't get it to work. It seems to change the renderer (I confirm by looking in the render settings before and after running the script) but the actual render happens with the software renderer. What am I doing wrong?

import maya.cmds as cmds
import maya.mel as mel

class RenderTest():
  def __init__(self):
    # Set renderer to Maya's Hardware 2.0.
    cmds.setAttr("defaultRenderGlobals.currentRenderer", "mayaHardware2", type = "string")
    mel.eval('setCurrentRenderer "mayaHardware2";')
    mel.eval('setAttr hardwareRenderingGlobals.renderMode 2;')

    # Set output image format to PNG.
    cmds.setAttr("defaultRenderGlobals.imageFormat", 32)

    # Render a camera view.
    cmds.render("persp", x = 1920, y = 1080)

    # Save the result to file.
    cmds.renderWindowEditor("renderView", e=True, writeImage = "C:/render.png")
0 Likes
Accepted solutions (1)
847 Views
1 Reply
Reply (1)
Message 2 of 2

Kahylan
Advisor
Advisor
Accepted solution

Hi!

 

The problem lies with the "cmds.render" command, as this command uses Maya Software exclusively. if you want to render using the Hardware Renderer instead use "cmds.hwRender".

 

https://help.autodesk.com/cloudhelp/2022/ENU/Maya-Tech-Docs/CommandsPython/

 

I hope this helps!

0 Likes