way to delete shading nodes

27 views
Skip to first unread message

James Kim

unread,
Dec 17, 2018, 2:00:45 PM12/17/18
to Python Programming for Autodesk Maya
I have a code where I create a shader and apply it to an object.
However when i run the code again it creates entirely new nodes and applies to the object.
Is there a way to delete the previous node so it doesnt clog up the hypershade?

exampleCode:
testPlane = cmds.polyPlane(name = 'test', width = widthTop/100, height = heightTop/100, sx=0, sy = 0)
shaderT = cmds.shadingNode('testNode', asShader=True)
shading_group1 = cmds.sets(renderable=True, noSurfaceShader=True, empty=True)
cmds.connectAttr('%s.outColor' % shaderT, '%s.surfaceShader' % shading_group1)
cmds.select('test')
cmds.hyperShade(assign = shading_group1)


Michael Boon

unread,
Dec 17, 2018, 3:42:41 PM12/17/18
to Python Programming for Autodesk Maya
The easiest way to find the material on a shape is to select it and then use the hypershade command:
cmds.hyperShade(shaderNetworksSelectMaterialNodes=True)
materials
= cmds.ls(sl=True)

From there you can find shadingEngines using something like
cmds.listConnections(m, source=False, type='shadingEngine')
(though beware, some of those might be the swatch shader in the Hypershade, which you can't delete)

and then in the other direction, find the incoming connections to the material:
cmds.listConnections(m, destination=False)
and for each of those connections, you probably want to look at its incoming connections and delete those, etc. There are a few things you need to avoid following, like references.

I hope that helps.
Reply all
Reply to author
Forward
0 new messages