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.
On Tuesday, 18 December 2018 06:00:45 UTC+11, James Kim wrote:
>
> 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)
>
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/7184cfea-bd73-4bd2-afb8-9836e30c4687%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.