# Query Vertex Color

**URL:** https://forum.highend3d.com/t/query-vertex-color/2566
**Category:** Maya
**Tags:** mel
**Created:** [December 31, 2006, 5:02am UTC](https://forum.highend3d.com/t/query-vertex-color/2566 "2006-12-31T05:02:01Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![francisbitonti](https://forum.highend3d.com/user_avatar/forum.highend3d.com/francisbitonti/32/54705_2.png) [@francisbitonti](https://forum.highend3d.com/u/francisbitonti)
#### Post date: [December 31, 2006, 5:02am UTC](https://forum.highend3d.com/t/query-vertex-color/2566/1 "2006-12-31T05:02:01Z")

</div>

I am having a dificult time understanding the data types used when trying to query the color of a vertex. what kind of data is returned and how do you use it?

I am writing this littel script that querys a mesh loooking for a vertex in which the green attribute is equal to one.

The error I get is

// Error: Cannot use data of type float[] in a scalar operation. //

How do I convert the output into something that will work. I can't believe that I have never had to convert data types in mel before so i'm a bit lost. Thanks for any help you can give.

CODE  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string $intSelection[] = `ls -sl -fl`;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;polyColorPerVertex -g 1;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;polySelectConstraint -m 3;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string $revSelection[] = `ls -sl -fl`;  
//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print $revSelection[0];  
//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print $revSelection[1];  
//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print $revSelection[2];  
//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print $revSelection[3];

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select -cl;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//path to file  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$filename = ("C:/2dTrussLoads.txt");

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int $i;

&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;float $colorQuery;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// open the file for writing  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$file = `fopen $filename "w"`;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;global float $neigh1;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;global float $neigh2;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// fprint  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprint $file ( "Nodal Loads" + "\n" );

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while($i \< size($revSelection)){  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select -r $revSelection[$i];  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//$colorQuery[0] = `polyColorPerVertex -q -g`;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(`polyColorPerVertex -q -g` == 1){  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprint $file ( $neigh1 + "\n" );  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprint $file ( $neigh2 + "\n" );  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(`polyColorPerVertex -q -g` == 0){  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprint $file ( "0" + "\n" );  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprint $file ( "0" + "\n" );&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$i = $i + 1;  
&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// close file  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fclose $file;  
}

---

<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: [December 31, 2006, 10:51am UTC](https://forum.highend3d.com/t/query-vertex-color/2566/2 "2006-12-31T10:51:55Z")

</div>

getAttr and most other mel commands deals with arrays (mel is a language that acts on arrays), in fact maya internally represents stuff as compounds and they arent of mel understandable type.

now (`polyColorPerVertex -q -g` == 1) its like asking is a passanger plane equal to a dog.

Now polyColorPerVertex -q -g returns a array of a value for each selected vertex or vertexface. As such ist probably better taht you not rely on this mechanism but rtaher explicitly pass the polyColorPerVertex a querry set. but fine.

It does not even matter if you just querry one value, its still a array with size 1. Now its not very good idea to ask for the value of eactlly 1, because if its painted in its realy realy RARE indeed

CODE  
{  
 for ($item in `ls -sl -fl`){  
 $color=`polyColorPerVertex -q -g $item`;  
&nbsp;&nbsp; if( $color[0]\> 0.9){  
&nbsp;&nbsp;&nbsp;&nbsp; print ( "yes\n" );  
&nbsp;&nbsp; }else{  
&nbsp;&nbsp;&nbsp;&nbsp; print "no\n";  
&nbsp;&nbsp; }  
 }  
}

Tough if you ask the whole mesh you should realy do:

CODE  
{  
 for ($item in `polyColorPerVertex -q -g`){  
&nbsp;&nbsp; if( $item\> 0.9){  
&nbsp;&nbsp;&nbsp;&nbsp; print ( "yes\n" );  
&nbsp;&nbsp; }else{  
&nbsp;&nbsp;&nbsp;&nbsp; print "no\n";  
&nbsp;&nbsp; }  
 }  
}

its faster, MUCH faster, also you should do writes in chunks a small wirte like that can be a bit slowing even if its cached.
