Simply Maya User Community

Simply Maya User Community (https://simplymaya.com/forum/index.php)
-   Maya Basics & Newbie Lounge (https://simplymaya.com/forum/forumdisplay.php?f=31)
-   -   Multi-assign new materials to a number of objects? (https://simplymaya.com/forum/showthread.php?t=41201)

gubar 29-01-2015 11:50 AM

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

stwert 29-01-2015 02:06 PM

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
}


gubar 29-01-2015 02:15 PM

Wow, that was awesome and fast, thank you so much Stewrt :)

Much appreciated, does exactly what I needed!

thank you

gubar

adev 29-05-2021 10:29 AM

Quote:

Originally Posted by stwert (Post 357655)
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
}


such a lifesaver little script.. should be there in hypershade menu by default!
Thanks


All times are GMT. The time now is 10:29 PM.

Powered by vBulletin® Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.
Simply Maya 2018