Thread: Mel scripting
View Single Post
Old 08-03-2011, 01:57 PM   #4
Registered User
Join Date: Mar 2011
Posts: 4
Thanks: 0
Thanked 2 Times in 2 Posts

Hi Laurie,

I have searched many forums and read hundereds of lines of code and finally built a script that works for this task.

The task is to select each and every poly face that faces the x axis only,
The useful purpose for this is to select all x facing poly faces of a structural mesh like a house and uv project in that axis. Once you have the x axis projected you can manually invert your selection and project for the z axis very easily, and the y axis is a breeze.

I am new to mel so please excuse the amature code:

//__________________________________________________ ______________________________________________
//Select all the X facing faces of a poly mesh selection
//created by: bikehawk
//date: 08-03-2011

//Select one poly mesh
select -r pCube1 ;
//list the selection
string $selection[] = `ls -sl`;
print $selection;

//Select all the faces of an object
select -r $selection.f["*"];

//add a line
print ("\n");

//now get and display the individual number of faces in the selection
string $faceList[] = `filterExpand -sm 34`;

print $faceList;

//add a line
print ("\n");

//declare a variable with the number of faces
$nof = (size($faceList));

//variable to loop the for loop the correct amount of times
$nofLoop = $nof - 1;

//print the number of faces
print ("Num of faces is: " + $nof + "\n");

//select the cube to clear the face selection
select -r pCube1 ;

//Start the FOR LOOP*************************
for ($i=0;$i<=$nofLoop;$i=$i+1)
print $faceList[$i];
print ("\n");

//get all the face normal vectors
string $polyInfo[] = `polyInfo -faceNormals $faceList`;

//specify 1 face normal vector
$polyInfo = stringToStringArray($polyInfo[$i]," ");

//put vectors into variables
float $vPosX = $polyInfo[2];
float $vPosY = $polyInfo[3];
float $vPosZ = $polyInfo[4];

if ($vPosX >= 0.5)

print ("Select this face: " + $faceList[$i]);
select -tgl ($faceList[$i]);
if ($vPosX <= -0.5)
print ("Select this face: " + $faceList[$i]);
select -tgl ($faceList[$i]);

//add a line
print "\n";

//end the FOR LOOP*************************


Hope this helps a few people, and any comments or code cleanup are very welcome.
Cheers guys
bikehawk is offline   Reply With Quote
The Following User Says Thank You to bikehawk For This Useful Post:
David (08-03-2011)