To know the material to one object

Please I need the function that retrieve me the material that have one object in particular, please need help

ASK THE MATERIAL with the name of the object

Thanks for all and for my bad english

Select your object and then run this script.

$shape=ls -dag -shapes -sl;
$shadingEngine = listConnections -source true -type shadingEngine $shape;
$shader =listConnections -source true -destination false ($shadingEngine[0] +".surfaceShader");
print($shader);

Good luck,
ww

Thanks for all

Best reggards

Thanks for all

Best reggards

Funny, this just came up in a different forum the other day, and I whipped this up.

It's very close to empleh's solution but different in a few important ways:

1) first off, the results for ls and listConnections must be put in an array. Maya will give you an error if those variables are not defined as arrays.

2) Second, doing an ls -dag -shapes gives you ALL the shape nodes under the current selection. If you have fifteen objects parented under the current object, you'll get a list of all of those shapes. What I did was use listRelatives -children -shapes to get the shape nodes directly underneath the current transform. (Of course, since I'm only looking at the first one I find, this doesn't matter much, but if you're going to loop over the list, it will matter.)

3) I didn't bother with the -source true and -destination false. Not sure I know of a situation where they're necessary, but anything's possible I guess.

proc string getSurfaceShader (string $objName) {

// This assumes you want ONLY the shape node at the selected level of the
// hierarchy, for the object whose transform name is passed in as the argument.

string $myShapeNode[] = listRelatives -children -shapes $objName;
string $mySGs[] = listConnections -type shadingEngine $myShapeNode[0];
string $surfaceShader[] = listConnections ($mySGs[0] + ".surfaceShader");
return $surfaceShader[0];
}

-- Mark


Mark R. Wilkins
author of MEL Scripting for Maya Animators
www.melscripting.com