Hello,
I am learning python with Maya. The problem I have with the following code is that the shader is
deselected when objects are selected. If I reverse command order, objects are deselected when shader is selected and thus can’t make shader assignment. I’m sure the code is basic, but all the code I have found thus far is more complicated, and when I paste it into script editor, I get errors that I can’t seem to solve at my level. Any advice is appreciated.
CODE
import maya.cmds as mc
mc.polyCube(h=5, w=3, d=3)
mc.polySphere(n=‘bola’)
mc.move(0,7,0)
mc.duplicate()
mc.move( 0, 3, 0, relative=True)
mc.duplicate( st=True )
mc.duplicate( st=True )
mc.shadingNode(‘blinn’, asShader=True)
mc.select(‘blinn1’)
mc.select(allDagObjects=True)
#mc.sets() COULD BE HELPFUL - NOT NECESSARY
mc.hyperShade( ‘blinn1’, assign=True )
###ERROR MESSAGE #Error: line 1: No shader is selected to be assigned
Replies
I forget the syntax etc. So you'll have to look it up.
- import maya.cmds as mc
-
- mc.polyCube(h=5, w=3, d=3)
- mc.polySphere(n="bola")
- mc.move(0,7,0)
- mc.duplicate()
- mc.move( 0, 3, 0, relative=True)
- mc.duplicate( st=True )
- mc.duplicate( st=True )
- myBlinnShader = mc.shadingNode("blinn", asShader=True)
- mc.select(allDagObjects=True)
- mc.hyperShade( assign=myBlinnShader )
Should work now. Basically you store the shading network in a variable (myBlinnShader in this case) and assign it. Hypershade will assign the shader to the meshes selected so no need to select the material. This would be the most straight forward/basic way but the better future way to do it is with sets when you need to do like multiple materials within a single object.