SimplyMaya Forums

Welcome to the forum, feel free to ask questions here.


SM Forums / Lounges / Maya Basics & Newbie Lounge / Multi-assign new materials to a number of objects?

Maya Basics & Newbie Lounge 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.

Join the conversation. Reply to post
 
Thread Tools
29-01-2015, 11:50 AM   #1
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
  Reply with quote
29-01-2015, 02:06 PM   #2
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
}
  Reply with quote
29-01-2015, 02:15 PM   #3
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
  Reply with quote
29-05-2021, 10:29 AM   #4
adev
Registered User
 
Join Date: May 2021
Posts: 1
Quote:
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
  Reply with quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to reflect the number of objects together with animation mirror Laguna90 Animation 0 24-06-2016 02:43 PM
group of materials - like multi mat in 3dsx max frankm Maya Basics & Newbie Lounge 0 18-03-2014 02:03 PM
Problem to assign materials MademoiselleEve Maya Basics & Newbie Lounge 6 24-09-2011 08:13 PM
Large number of dynamic objects InverseTelecine Dynamics & Special Effects 15 24-03-2009 09:22 AM
Can I assign two or more materials to one Nurbs surface? bettery_wn Maya Technical Issues 7 24-03-2003 03:02 AM