PDA

View Full Version : API: Get assigned Material


AyaKoshigaya
01-10-2005, 12:30 PM
Hi,

does anyone know how I can get the to an Object assigned material.. (eg. Lambert1)??? (In API)

Au'revoir,
Aya~

tomViolet
01-11-2005, 01:07 PM
this worked on a quick test I did but I can't imagine it would work on a more coplex structure.
I think the way to go around this is to check the connections of the shape of the object until you find the shaderEngine and then list the connections again to find the material that is connected to that shaderEngine.


// get selection
string $sel[] = `ls -sl -fl`;

// check if selection is the shape, if not get the shape of the selection
if(`nodeType $sel[0]` == "transform")
$sel = `pickWalk -d down`;

// list connections of type "shadingEngine"
string $connections[] = `listConnections -t "shadingEngine"`;

// if no shading engines found quit script.
if(!size($connections))
error "no shaders attached";

string $shaderEng = $connections[0];

// get the node that is connected to the shading engine's surfaceShader attribute
$connections = `listConnections -source 1 -destination false ($shaderEng + ".surfaceShader")`;

// $shNode is the name of the material attached to the object
string $shNode = $connections[0];


any questions feel free to ask.

mhovland
01-11-2005, 02:48 PM
What tomViolet wrote looks like it will work, of course this is using MEL, which you are able to do through the API, but it can be slow. I would recommend trolling through the API docs to find out how to do this strictly in a plugin.

AyaKoshigaya
01-12-2005, 05:44 AM
Hi,

thanks ^^ but i need it in API anyway.. won't use MEL via API :)

I've done it allready trough looking at the Conenctions via API and so I can get the SG... but i hope there's still a better way ^^

Au'revoir,
Aya~

CGTalk Moderation
01-20-2006, 09: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.