PDA

View Full Version : Request: MEL for Check Object For Default Material Assigned


projectironwill
01-18-2006, 10:23 PM
If an artist creates an object, then goes straight to the Create PSD network, all future objects created in Maya 7 will have the PSD network assign to that object which was formally the default gray lambert1. I want to create a shelf button that first checks to see if the material assign to the one single selected object is the default lambert1 or not. If so, then create an Dialog window that alerts the artist to assing a new material first and then try creating a PSD Network. Here's my wish list that I need created in MEL:

//Script concept workflow
if
selected object is using the default lambert material.
Create a dialog box "Assign New Material"

else
photoShopPaintTex;

Dream List:
Inside the Assign New Material dialog, have it where there is are buttons to assign either a new Lambert, a Blinn, an Anisotropic or a Phong to the selected object and then run the photoShopPaintTex; command. But first, since the photoShopPaintTex; command requires only one item, that would need to be tested in the very beginning to be sure the artist doesn't assign a new shader to more than one object and then get an red Error: No object has been selected / More than one object has been selected in the Command Feedback about the photoShopPaintTex;

//Script concept workflow

$sel = selection count.
if $sel != to 1
create dialog1 box "You have $sel objects selected"
"Select One Object for Texturing"
button [Close]. // kill the script.

if selection is == to default lambert
create dialog2 box "Assign a New Material"
"[Anisotropic]" "[Blinn]" "[Lambert]" "[Phong]" "[Cancel]"

//For each material button add the photoShopPaintTex; command
at the end of each button command so that once the material has
been assigned, the script goes onto to the normal Create PSD Network
for the artist.


Thanks for any and all help!

jtilden20
01-19-2006, 04:51 AM
My apologies if I sound like I'm talking down to you... I'm merely providing a resource to others using you're immediate needs as an example. :)

If you're a scripting noob, this is a good exercise in understanding node/connection relationships in Maya becuase what you're looking for pretty much requires you to down a list of connections to find the nodes you're interested in.

First step, learn to use the hypergraph if you aren't that familar with it. Being able to visualize the connections and see the input and outputs is pretty useful in understanding whats going on under the hood. If you wish to see which nodes are connected to a particular object, simply select your object and open the hyper graph. There should be a button that looks like a pod racer from Star Wars (the actual text on the mouse over reads "Input and Output Connections"). This mode will tell you what is connected to your object.

If you create a sphere you should see a few nodes in the hypergraph:


pSphere1- the transform node- contains your translation, orientation, scale info
polySphere1- the polySphere node- this is really just the thing that initially tells the sphere what its radius should be, number of horizontal and vertial subdivisions, etc
polySphereShape1- The shape node- has all the vertex, face, edge, shading info
initialShadingGroup- The node that contains set information about which objects and object compnents are belong to a particular material

Now in the case of projectironwill's problem, we're going to be dealing with the materials on an object. Normally when you select an object in the viewport, you almost always select the transform node (pSphere1). So the first part of your script should be obtaining the shape node (since thats what materials are really connected to). To obtain the shape node, you need to listRelatives of the transform. Here's an example:

//Find the shape node of a polymesh
proc string findShape( string $object )
{
//Check to see if its not already a polymesh
if ( `objectType $object` == "mesh" )
return $object; //If its already a shape, simple return the object

//Get a list of children for this object. Shape
//Nodes are generally direct children of a transform
string $shapes[] = `listRelatives -children -shapes -path $object`;

//Generally there is only one shape, but not always :)
if (`size $shapes`)
return $shapes[0];
else
{
warning "Could not determine the shape node!";
return ""; //Return nothing
}
}


Now that we have our shape node, we will need to peek at its connections to see if it has any materials assigned. We will do this using the listConnections command. Here is another example:


//Returns a string array with the attached shading group
proc string[] findAttachedShadingGroups( string $shapeNode )
{
//Shading groups are of node type shadingEngine
string $shadingGroups[] = `listConnections -type shadingEngine $shapeNode`;
return $shadingGroups;
}


If you're checking to see if this object is attached the default material, all you have to do is check to see if one of the attached shaders is called initialShadingGroup. If thats the case, then at this point you can call up your dialog box.

But what if you want to find what material is connected to an object? Then simply walk the connections of the shading group (similar to what we did to find the shading group from the shape node) to figure out the material. Although, figuring out which materials are connected to which faces, thats a more complicated problem for another time. Hope this helps!


-Jon

PS: The Maya Node and Attribute reference is great for figuring out what certain node types are and what they do. Also, objectType and nodeType are two excellent commands to figure out what the hell your object is.

jtilden20
01-19-2006, 04:57 AM
Deleting do to duplicate post.

CGTalk Moderation
01-19-2006, 04:57 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.