SimplyMaya

Welcome back to SimplyMaya. Check out our latest training here.

MAYA TUTORIALS
Please post in this section ONLY if your question doesn't fit in anywhere else on the forum, or if you're not sure which section it's relevant to. We also have Free streaming trial available.
 
Thread Tools
# 1 29-01-2015, 11:50 AM
gubar
Registered User
Join Date: Mar 2007
Posts: 1,055

Multi-assign new materials to a number of objects?

Hi,

instead of assigning each object a new material individually, is there a way to assign a unique material to all objects in a scene?

For my purposes it doesn't matter what the material is, just that every one is unique to the object it's assigned too.

If anyone can help out I'd really appreciate it,

thank you,

g

# 2 29-01-2015, 02:06 PM
stwert
EduSciVis-er
Join Date: Dec 2005
Location: Toronto
Posts: 3,374
A little script should be just the thing:

Code:
string $selectedObjs[] = `ls -sl`; //get selected objects
for ($obj in $selectedObjs){ //iterate on selected objects
	string $newMat = `shadingNode -asShader "lambert"`; //create a lambert
	string $rnMat = `rename $newMat ($obj + "_Lmb_Mat")`; //rename new material based on object [optional]
	string $newSG = `sets -renderable true -noSurfaceShader true -empty -name ($rnMat + "SG")`; //create a shading group
	connectAttr -f ($rnMat + ".outColor") ($newSG + ".surfaceShader"); //connect shading group to lambert
	sets -e -forceElement $newSG $obj; //connect material to object
}

# 3 29-01-2015, 02:15 PM
gubar
Registered User
Join Date: Mar 2007
Posts: 1,055
Wow, that was awesome and fast, thank you so much Stewrt

Much appreciated, does exactly what I needed!

thank you

gubar

# 4 29-05-2021, 10:29 AM
adev
Registered User
Join Date: May 2021
Posts: 1

A little script should be just the thing:

Code:
string $selectedObjs[] = `ls -sl`; //get selected objects
for ($obj in $selectedObjs){ //iterate on selected objects
	string $newMat = `shadingNode -asShader "lambert"`; //create a lambert
	string $rnMat = `rename $newMat ($obj + "_Lmb_Mat")`; //rename new material based on object [optional]
	string $newSG = `sets -renderable true -noSurfaceShader true -empty -name ($rnMat + "SG")`; //create a shading group
	connectAttr -f ($rnMat + ".outColor") ($newSG + ".surfaceShader"); //connect shading group to lambert
	sets -e -forceElement $newSG $obj; //connect material to object
}

Originally Posted by stwert View Post
such a lifesaver little script.. should be there in hypershade menu by default!
Thanks

Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off