what is the python command line to create a MATERIAL OVERRIDE in a collection of a render layer ?

what is the python command line to create a MATERIAL OVERRIDE in a collection of a render layer ?

maximeneko
Participant Participant
2,443 Views
2 Replies
Message 1 of 3

what is the python command line to create a MATERIAL OVERRIDE in a collection of a render layer ?

maximeneko
Participant
Participant

I'm trying to rephrase my question. what I want to do seems simple. but I can't find documentation precise enough for that. i just want to know the command line. 

 

import maya.app.renderSetup.model.renderSetup as renderSetup
rs = renderSetup.instance() 
rl = rs.createRenderLayer("newRenderLayer")
nc = rl.createCollection('redCollection')
mo = nc. ???????????????? ()

 

 

0 Likes
2,444 Views
2 Replies
Replies (2)
Message 2 of 3

Christoph_Schaedl
Mentor
Mentor

I got a reply in an other Thread. Maybe that does help your.

 

 

import maya.app .renderSetup.model.override as override
import maya.app .renderSetup.model.selector as selector
import maya.app .renderSetup.model.collection as collection
import maya.app .renderSetup.model.renderLayer as renderLayer
import maya.app .renderSetup.model.renderSetup as renderSetup
import maya.cmds as cmds

# Helper function for creating a shader
def createShader(shaderType):
    """ Create a shader of the given type"""
    shaderName = cmds.shadingNode(shaderType, asShader=True)
    sgName = cmds.sets(renderable=True, noSurfaceShader=True, empty=True, name=(shaderName + "SG"))
    cmds.connectAttr(shaderName + ".outColor", sgName + ".surfaceShader")
    return (shaderName, sgName)
	
# Helper function for assigning a material
def assignMaterial(shapeName, shadingGroupName):
    cmds.sets(shapeName, forceElement=shadingGroupName)
	
# Helper function for setting a color attribute to some color value
def setColor(attr, color):
    cmds.setAttr(attr, color[0], color[1], color[2], type="float3")
	
rs = renderSetup.instance()    

# Create and append the render layer
rl = rs.createRenderLayer("MyRenderSetupLayer")

# Create and append 2 collections
c1 = rl.createCollection("sphereCollection")
c2 = rl.createCollection("cubeCollection")

# Create a trivial scene with a cube, a sphere and a cylinder
cmds.polySphere(name='mySphere')
cmds.move(2, 'mySphere', y=True)
cmds.polyCube(name='myCube')
cmds.move(5, 'myCube', y=True)
cmds.polyCylinder(name='myCylinder')
cmds.move(10, 'myCylinder', y=True)

# Set up collection 1 to select all spheres using the pattern mySphere*, 
# and collection 2 to select all cubes using the pattern myCube*.
c1.getSelector().setPattern('mySphere*')
c2.getSelector().setPattern('myCube*')

# Set up an absolute override on mySphereShape.template with a value of True
ov1 = c1.createAbsoluteOverride('mySphereShape', 'template')
ov1.setAttrValue(True)

# Set up a relative override on myCube.translate with a multiply value of
# [2.0, 2.0, 2.0] and an offset of [0.1, 0.1, 0.1]
ov2 = c2.createRelativeOverride('myCube', 'translate')
ov2.setMultiply([2.0, 2.0, 2.0])
ov2.setOffset([0.1, 0.1, 0.1])

# Creates two surface shaders. Makes one red, the other blue and assigns the
# red shader to myCubeShape. Then creates a shader override with the blue
# shader.
shaderName, sgName = createShader("surfaceShader")
shaderName2, sgName2 = createShader("surfaceShader")
assignMaterial("myCubeShape", sgName)
setColor(shaderName + ".outColor", [1.0, 0.0, 0.0])
setColor(shaderName2 + ".outColor", [0.0, 0.0, 1.0])
outColorShaderOvr = c2.createAbsoluteOverride(shaderName2, 'outColor')

# Set the render layer as visible. 
# Only the sphere and the cube are displayed as they are collection members.
rs.switchToLayer(rl)

----------------------------------------------------------------
https://linktr.ee/cg_oglu
0 Likes
Message 3 of 3

maximeneko
Participant
Participant

Ho great. Your answer is complementary to the solution I found. Thank you very much.

0 Likes