I'm creating a tool for a homework assignment to create and apply materials to selected faces of target objects. The idea is that you'll be able to select faces, type in a name, pick a colour, and it will create and apply the material to the selected faces/objects in your scene. I can't quite figure out how to apply the material to the selected faces though...
So far I've created the material, created a shading group for the material, connected the material to the shading group, and changed the colour. I'm pretty new to scripting with python, so I'm having a hard time finding which command of many will actually apply my new material to my selected faces.
#create a shader (material)
shader=cmds.shadingNode('blinn', asShader=True, n="Wood") #placeholder name
#create a shading group
shading_group=cmds.sets(renderable=True, noSurfaceShader=True, empty=True)
#connect the shader to the shading group
cmds.connectAttr('%s.outColor' %shader, '%s.surfaceShader'%shading_group)
#Change the colour
cmds.setAttr(shader+'.color', R,G,B) #replace r,g,b with values between 0 and 1
selected= cmds.ls(sl=True)
All of my current code works so far, but I don't know what command to use to apply the material to my selection.
I've so far looked at cmds.hyperShade, cmds.setAttr, and cmds.sets but I don't know what to make of what my console is spitting out