View Full Version : Finding Object's Shader


trancor
08 August 2007, 09:54 PM
Hey, wanted to know how to quarry an objects shader.

I've tried stuff like listing connections because I notice in the connection editor it's an array for the shape's connection to the shader group itself, instObjGroups[0]. Tried that, didn't quarry anything. The closest I've come is getting a boolean saying that there is something connected yeilding a 1. I've looked through sets, characters, setAttr, and some more. Damn it why can't I just quarry on the hyperShade command..... That is going on the list of things to change for maya 9.....

I just want to quarry what shader is on an object.

trancor
08 August 2007, 10:01 PM
Know what, I should have just looked alittle harder, I forgot about the list history command.


so if anyone has the same problem that I just had -

string $shade[]=`listHistory -future true pSphere1`;


and it will list them out for you like listRelatives -ad would, it'll give you the shape and the shader in an array.

kungfuelmosan
08 August 2007, 10:05 AM
Hey dude a simple way is:

select $obj;
string $shaderS = `hyperShade -smn`;
string $shaderA[] = `ls -sl`;
string $shader = $shaderS[0];

(or something like that)

kinda bodjey but saves you having to query the shadingGroups members etc.

ewerybody
08 August 2007, 09:08 AM
hyperShade -smn works. but thats the dirty way ;]
If you really want to querry:
you have to go through sets (or "shadingGroup" or "Engine" like its called here, afterall its just a set) :

Ok, lets assume you have your transforms selected. Now you have to get the connected shapes:

{
// get polyshapes from selection:
string $shapes[] = listRelatives("-f","-shapes", "-type", "mesh");
// Now collect the connected shadingGroups for these shapes:
string $shadingGroups[];
for ($shape in $shapes)
{
// look for all faces inside a shape, because shapes can also be connected
// without having any face attached to the shading group! You wouldn't want that:
$shadingGroups = stringArrayCatenate($shadingGroups,`listSets -type 1 -object ($shape + ".f
")`);
}
// ls has a useful -materials flag. With listConnections we could
// only use "-type lambert" but that'd exclude some shaders
string $shaders[] = ls("-materials",`listConnections $shadingGroups`);

print $shaders;
}Of course you could also lock in your transforms in a variable into listRelatives as well. This works without changing selection like hyperShade does. It would also work in batch mode. what hyperShade would not support.

without the comments and the {} its also just a 5 liner :)

CGTalk Moderation
08 August 2007, 09:08 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.


1