[Maya-Python] Render Setup Python API absolute override assign material

894 views
Skip to first unread message

Stefan Tapper

unread,
May 2, 2018, 4:51:55 AM5/2/18
to Python Programming for Autodesk Maya
Hello fellow Maya heads,

I've recently started to dive into Maya standalone land and was so adventurous to work with the unsupported render setup API. (http://help.autodesk.com/view/MAYAUL/2017/ENU/?guid=GUID-FFC3298A-9803-4EAF-B472-D13247319EB0)

Can anyone point me to an working example how to connect a material override to a shadingEngine?
Right now, my code looks like this(method of a class creating a render setup):
@staticmethod
def create_material_override(collection, shading_group, name):
   
"""
        Creates a material override for the provided collection and
        assigns it to the provided shadingEngine.
    """

   
# Create material override
    __ovr
= collection.createOverride(name, typeIDs.materialOverride)

   
# Connect shadingEngine to override
   
try:
       
# Maya 2017 Update 4
        __ovr
.setOverrideConnection(shading_group.name() + '.message', applyIt=True)
   
except Exception as e:
       
# Pre Maya 2017 Update 4
       
# 2017 Update 3 also has a setMaterial method
        LOGGER
.debug(e)
        __ovr
.setSource(shading_group.name() + '.message')

   
return __ovr

This is working in Maya 2017 Update 4 but throws all kind of "Python Callback failed" errors on Maya 2016.5 (Extension 2 SP2).

Is there a better way to connect the override? I -think- I can not simply connect it via cmds or OpenMaya API2 since the render setup objects are only available thru the render setup API.

Cheers, Stefan

Stefan Tapper

unread,
May 2, 2018, 4:55:42 AM5/2/18
to Python Programming for Autodesk Maya
^^Forgot to mention the imports in the code example:
import maya.app.renderSetup.model.renderSetup as renderSetup
from maya.app.renderSetup.model import typeIDs


Reply all
Reply to author
Forward
0 new messages