Arturo
Arturo

Reputation: 171

Maya creating shader with cmds does not appear in hypershade

using maya 2014/2015 creating a shader like so:

import maya.cmds as cmds
my_shader = cmds.createNode('lambert', n='mine')

will create this result. enter image description here

anybody knows how to get that shader to be reflected in the hypershade?

Upvotes: 1

Views: 1946

Answers (2)

Fnord
Fnord

Reputation: 5905

Adding to the answer for completeness:

In some cases (namely ShaderFx shaders) you need to connect the material to the scene's defaultShaderList1 node's next available plug.

import maya.cmds as mc

material = mc.shadingNode('lambert', asShader=True)
shading_engine = mc.sets(name="%sSG" % material, empty=True, renderable=True, noSurfaceShader=True)
mc.connectAttr('%s.outColor' % material, '%s.surfaceShader' % shading_engine)
mc.connectAttr('%s.msg'%material, ':defaultShaderList1.s', na=True)

Upvotes: 1

theodox
theodox

Reputation: 12218

shaders are a slightly different node type:

cmds.shadingNode('lambert', asShader=1)

You'll also need to create a shadingEngine node, what we usually know as ShaderGroups or SG`s:

cmds.shadingNode('shadingEngine', asUtility=1)

and connect the .outColor of the shader to the .surfaceShader attribute of the SG. The SG node is actually a subclass of a Maya set, and to assign objects or faces to it use the sets command.

Upvotes: 2

Related Questions