Create shaders through Python

Here’s a quick script to create a simple shader via Python.

import maya.cmds as cmds
#create a shader
shader=cmds.shadingNode("blinn",asShader=True)
#a file texture node
file_node=cmds.shadingNode("file",asTexture=True)
# a shading group
shading_group= cmds.sets(renderable=True,noSurfaceShader=True,empty=True)
#connect shader to sg surface shader
cmds.connectAttr('%s.outColor' %shader ,'%s.surfaceShader' %shading_group)
#connect file texture node to shader's color
cmds.connectAttr('%s.outColor' %file_node, '%s.color' %shader)
Advertisements

One thought on “Create shaders through Python

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s