Skip to content

Instantly share code, notes, and snippets.

@mfessenden
Last active May 17, 2024 08:49
Show Gist options
  • Save mfessenden/71e2166c16fbcf7e8cf8 to your computer and use it in GitHub Desktop.
Save mfessenden/71e2166c16fbcf7e8cf8 to your computer and use it in GitHub Desktop.
Maya command to create a lambert shader & shading group node named for the object
import maya.cmds as mc
def applyMaterial(node):
if mc.objExists(node):
shd = mc.shadingNode('lambert', name="%s_lambert" % node, asShader=True)
shdSG = mc.sets(name='%sSG' % shd, empty=True, renderable=True, noSurfaceShader=True)
mc.connectAttr('%s.outColor' % shd, '%s.surfaceShader' % shdSG)
mc.sets(node, e=True, forceElement=shdSG)
applyMaterial("pSphere1")
@saliwillient
Copy link

Many thanks

@LSQsjtu
Copy link

LSQsjtu commented May 17, 2024

Is there any way to duplicate the shading node with all connectiones in maya cmds?

@BigRoy
Copy link

BigRoy commented May 17, 2024

Is there any way to duplicate the shading node with all connectiones in maya cmds?

Matching these menu entries:

maya_hypershade_duplicate

The logic is roughly:

Duplicate Shading Network

from maya import cmds
cmds.duplicate(upstreamNodes=True)

Duplicate without network

from maya import cmds
cmds.duplicate()

Duplicate with connections to network

from maya import cmds
cmds.duplicate(inputConnections=True)

@LSQsjtu
Copy link

LSQsjtu commented May 17, 2024

Thanks a lot. I need to duplicate the shading network. And I use the code cmds.duplicate([mtl, mtl_sg], upstreamNodes=True). It really works. Thanks for your reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment