# Getting objects with a specified material

**URL:** https://forum.highend3d.com/t/getting-objects-with-a-specified-material/5544
**Category:** Maya
**Tags:** mel
**Created:** [February 6, 2003, 4:00pm UTC](https://forum.highend3d.com/t/getting-objects-with-a-specified-material/5544 "2003-02-06T16:00:24Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![matt-lewis](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/m/db5fbb/32.png) [@matt-lewis](https://forum.highend3d.com/u/matt-lewis)
#### Post date: [February 6, 2003, 4:00pm UTC](https://forum.highend3d.com/t/getting-objects-with-a-specified-material/5544/1 "2003-02-06T16:00:24Z")

</div>

Hi.

I have the name of a specific material, and would like to get all the meshes that the material applies to.

e.g. given the material name "lambert2" I get the following results:

polySurface2248.f[201]   
polySurface2248.f[218:219]

I can get the information by using Multilister, but I'm trying to get the info via MEL.

Any help would be great, thanks.

---

<div class="post-metadata">

### Author: ![gdc](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/g/898d66/32.png) [@gdc](https://forum.highend3d.com/u/gdc)
#### Post date: [February 6, 2003, 4:56pm UTC](https://forum.highend3d.com/t/getting-objects-with-a-specified-material/5544/2 "2003-02-06T16:56:23Z")

</div>

here is one way, may not be the best method for what your doing, but it should work.

//-----  
hyperShade -objects lambert2;  
string $faces[]=`ls -sl`;

//------

Hope that helps  
--g

---

<div class="post-metadata">

### Author: ![ism](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/i/3e96dc/32.png) [@ism](https://forum.highend3d.com/u/ism)
#### Post date: [February 7, 2003, 7:05am UTC](https://forum.highend3d.com/t/getting-objects-with-a-specified-material/5544/3 "2003-02-07T07:05:34Z")

</div>

Agree with GDC.  
But if you work with polygons, i think it's beter to use   
"filterExpand -sm 34 -ex 1" instead of "ls -sl". It allows you to avoid such replies like "f[10:30]".

---

<div class="post-metadata">

### Author: ![joojaa](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@joojaa](https://forum.highend3d.com/u/joojaa)
#### Post date: [February 7, 2003, 10:17am UTC](https://forum.highend3d.com/t/getting-objects-with-a-specified-material/5544/4 "2003-02-07T10:17:29Z")

</div>

Or "ls -selection -flatten" Will give you the individual faces not aglob!

---

<div class="post-metadata">

### Author: ![gdc](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/g/898d66/32.png) [@gdc](https://forum.highend3d.com/u/gdc)
#### Post date: [February 7, 2003, 5:08pm UTC](https://forum.highend3d.com/t/getting-objects-with-a-specified-material/5544/5 "2003-02-07T17:08:41Z")

</div>

Agreed! but the orignal post said the results should be:

poly.f[218:220];

--g

---

<div class="post-metadata">

### Author: ![warpcat](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/w/c89c15/32.png) [@warpcat](https://forum.highend3d.com/u/warpcat)
#### Post date: [February 7, 2003, 9:30pm UTC](https://forum.highend3d.com/t/getting-objects-with-a-specified-material/5544/6 "2003-02-07T21:30:14Z")

</div>

Note: I've pasted my script in a couple times now, and every time I post it in, not only does the formatting get screwed up, but the "for" loops loose a bunch of their code. I aplogoize, but I don't know what's going on ![](http://64.32.63.100/forums/icons/frown.gif)

I have a proc written to do this stuff. Select a material from the Hypershade (not multilister... the multilister dosen't "select" things by default), and it will select the nodes it's assigned to, plus list them in the script editor:

global proc EP\_listShadedElements()  
 {  
 string $material[] = `ls -sl`;  
 if (size($material) != 1)  
 error "Please select only a single Material";  
 text -e -l ("Shader Name: " + $material[0]) T\_PSF\_shaderName;  
 string $destinationConnections[] = `listConnections -s 0 -d 1 $material[0]`;  
 for ($a=0; $a {  
 if (`objectType -i "shadingEngine" $destinationConnections[$a]`)  
 {  
 string $shadingEngine = $destinationConnections[$a];  
 string $setMembers[] = `sets -q $shadingEngine`;  
 for ($b=0; $b {  
 setParent CL\_PSFelements;  
 button -l ("Select: " + $setMembers[$b]) -c ("select -r " + $setMembers[$b]);  
 }  
 }  
 }   
 }

---

<div class="post-metadata">

### Author: ![matt-lewis](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/m/db5fbb/32.png) [@matt-lewis](https://forum.highend3d.com/u/matt-lewis)
#### Post date: [February 12, 2003, 3:35pm UTC](https://forum.highend3d.com/t/getting-objects-with-a-specified-material/5544/7 "2003-02-12T15:35:23Z")

</div>

Thanks for the replies, it's exactly what I needed.

---

<div class="post-metadata">

### Author: ![bentneuron](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/b/ea666f/32.png) [@bentneuron](https://forum.highend3d.com/u/bentneuron)
#### Post date: [June 1, 2003, 9:31pm UTC](https://forum.highend3d.com/t/getting-objects-with-a-specified-material/5544/8 "2003-06-01T21:31:37Z")

</div>

Hi Warpcat,

I'm still rather new to MEL and was wondering about your syntax here? The "for ($a=0; $a{" is confusing me...is it shorthand for something?

Thanks,  
-bN

---

<div class="post-metadata">

### Author: ![warpcat](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/w/c89c15/32.png) [@warpcat](https://forum.highend3d.com/u/warpcat)
#### Post date: [June 2, 2003, 7:39pm UTC](https://forum.highend3d.com/t/getting-objects-with-a-specified-material/5544/9 "2003-06-02T19:39:20Z")

</div>

You work at Spark? Ask Lonnie... he can tell you ALLLL about it. Tell him Warpcat in San Francisco says hi ![](http://64.32.63.100/forums/icons/wink.gif)
