PDA

View Full Version : query material


fbitonti
07-10-2007, 08:53 PM
I am totaly stumped on this one so any help would be great.

I have one polygon mesh each face in the mesh has it's own material assigned to it. I need to wite a script that will iterate through the mesh and select only the faces that have a particular material assigned to it. My question is this?

How can i query the material applied to a face and not the mesh?


Any help you can provide would be fantastic.

kjaft
07-11-2007, 09:44 AM
This is from Bryan Ewert's MEL How-To (can be found here (http://web.archive.org/web/20050904093539/www.ewertb.com/maya/mel/mel.php?howto=43)):


Getting the Assigned Shading Group for a Face Component


Get a list of all Shading Groups in your scene and query the membership for each set to check if the target component is shaded by that shader.

proc string getFacetSG( string $facet )
// Input (string) - facet component to query (e.g. "pSphere1.f[0]")
// Result (string) - Shading Group shading facet (e.g. "lambert2SG")
{
string $facetSG = "";

// Get array of all Shading Groups
string $shadingGroups[] = `ls -type shadingEngine`;

for ( $shadingGroup in $shadingGroups )
{
// If this facet is a member of the shading set for this
// Shading Group, tag this as the facet's shader
if ( `sets -isMember $shadingGroup $facet` )
{
$facetSG = $shadingGroup;
break;
}
}

return $facetSG;
}

mhovland
07-11-2007, 01:00 PM
Alternately you could get all the materials in the scene, loop through them and use the hyperShade command to select the objects with the material assigned, and then store the faces selected.......

Just another method..

CGTalk Moderation
07-11-2007, 01:00 PM
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.