Search code examples
pythonshadermayamaya-api

Maya Python - How to create shaderOverride?


Using python in Maya 2017, I'm able to reproduce the structure of my render_setup (layers, collections and overrides) except for shaderOverride.

For a classic override, I use the instance function : maya.app.renderSetup.model.collection.Collection.createOverride()

Is there a similar command to create a shader override or do you add some specific attributes?

Thanks


Solution

  • You need the MTypeId of the override you want to create. Find typeIDs.py in your Maya installation folder (.../lib/python2.7/site-packages/maya/app/renderSetup/model/typeIDs.py)

    As you can see, the MTypeId of a shader override is 0x58000386.

    Then, just create a layer and a collection, and call your createOverride method:

    from maya.app import renderSetup
    import maya.api.OpenMaya as OpenMaya
    
    renderSetup.model.renderSetup.initialize()
    rs = renderSetup.model.renderSetup.instance()
    
    # Create layer
    rsLayer = rs.createRenderLayer('MyFirstLayer')
    # Create collection
    rsColl = rsLayer.createCollection('MyFirstCollection')
    # Create shading override
    over_obj = rsColl.createOverride('MyFirstOverride', OpenMaya.MTypeId(0x58000386))
    

    If you want to create another override, just find the according MTypeId.