View Full Version : Find material on object

01 January 2005, 10:08 PM
I am trying to find the material of a selected object. This is how I am trying to do it but it does not seem to be working. I am just printing the variable at the end to test it. I have also tried one or two other things that did not work for me.

$selectedSkin = `ls -sl`;

$selectedMaterial= `ls -mat $selectedSkin`;

print $selectedMaterial;

Thanks for any help


01 January 2005, 02:29 AM
Here's somethoing quick and dirty. If I was doing this for real, I'd do a little more checks/verification. The concept is that the material connections are to the shape node of an object, not the transform. The connection to the shape is the shading engine, so once that is found, find the material. If anyone else has comments or something to add, please do so. Cheers!

string $objectShapes[];
string $shadingEngine[];
string $material[];

string $objects[] = `ls -sl`;

// Find the material for each object in the selected list
for ( $obj in $objects )
print ( "Object: " + $obj + "\t");

// If the object selected is a transform, find the shape node
if ( `objectType $obj` == "transform" )
$objectShapes = `pickWalk -d down $obj`;

// List connections of type Lambert, 'cause the basic materials
// are all derived from Lamberts
$shadingEngine = `listConnections -s false -d true -type shadingEngine $objectShapes[0]`;

if ( `objectType $shadingEngine[0]` == "shadingEngine" )
$material = `listConnections -type lambert $shadingEngine[0]`;

// Assign this to another variable
print ( "Material: " + $material[0] + "\n" );

01 January 2005, 11:18 PM
Mark, thanks for the help. I had put something together myself when you had posted.

$s=`ls -sl`;

$shade=`listSets -t 1 -ets -o $s`;

string $connections[] = `listConnections -d 0 -s 1 $shade`;

$material = $connections[0];

$transparency = $material+".transparency";

setAttr $transparency -type double3 .5 .5 .5;

Thanks again


CGTalk Moderation
01 January 2006, 10:00 AM
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.