PDA

View Full Version : material manipulation


kattkieru
07-04-2007, 12:03 PM
Heya all,

Sorry for such a noobish question, but I've recently gotten a request from a client to do some simple material stuff and it's my first time working with mats through MEL. =/

I was wondering: how do you find materials that are already in the scene? Let me start with the code I've been using to test:


shadingNode -asShader lambert -name fgs;
sets -renderable true -noSurfaceShader true -empty -name fgsSG;
connectAttr -f fgs.outColor fgsSG.surfaceShader;
setAttr "fgs.color" -type double3 0 0 0 ;

sets -e -forceElement fgsSG pPlane1;


I know it's a bad habit to use a hard-coded plane name, but I'm still just testing. Anyway, The above code works fine -- I get a pure black matierial attached to my object. However, the problem arises when I want to delete the plane and start again. If I don't delete the materials before re-running the script either the plane gets assigned a gray lambert (since the script uses hard-coded names for the material, the new material that gets generated does not get the color change), or there end up being a bunch of identical materials in the scene (which happens when I save the generated names).

So how can I find materials? "exists" returns 0. Thanks in advance.

mhovland
07-04-2007, 02:10 PM
Look at the ls command, you can ls specific things like -tex and -mat. That will get you all the materials in the scene, loop through them and delete your material.

Alternatively, since maya won't allow you to have two nodes named the same thing at the same level, you could just select your material directly and delete it.

kattkieru
07-07-2007, 03:57 AM
Ahh cool. Cheers mate, I'm going to give that a try in the morning. Thanks a bunch!

kattkieru
07-08-2007, 02:06 PM
I just wanted to post the code I used in case it saves anyone else some time:


string $shaders[] = `ls -mat`;
if (!stringArrayCount("myShader", $shaders)) {
shadingNode -asShader lambert -name myShader;
sets -renderable true -noSurfaceShader true -empty -name myShaderSG;
connectAttr -f myShader.outColor myShaderSG.surfaceShader;
setAttr "myShader.color" -type double3 0 0 0 ;
}

sets -e -forceElement myShaderSG $plane[0];

CGTalk Moderation
07-08-2007, 02:06 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.