//written by Ben Bathen January 17, 2003. //www.benbathen.com //this script cuts a polygonal object in half by deleting any face that is on the negative side of the X axis. global proc half() { //put the selected object into a string. string $sel[] =`ls -sl`; //create a set to hold the faces we will delete; string $badFaces[]; //find out how many faces are in the object. int $faceCount[] = `polyEvaluate -f $sel[0]`; //for every face on the object calculate the center point and delete it if its X coordinate is negative. int $i; int $b = 0; for ($i = 0; $i < $faceCount[0]; $i++) { //put the face into a string string $face = ($sel[0] + ".f[" + $i + "]"); //find the vertices that define that face. string $vertex[] = `polyListComponentConversion -ff -tv $face`; select $vertex; string $vertexFlat2[] = `ls -sl -fl`; //find out how many vertices define that face int $vertCount = `size $vertexFlat2`; //for each vertex go through and find it's world space position. place the x coordinate into a float. float $vertPosition[]; float $vertPositionSum = 0; int $a; for ($a = 0;$a < $vertCount; $a++) { float $coordinate[] = `pointPosition -w $vertexFlat2[$a]`; $vertPosition[$a] = $coordinate[0]; $vertPositionSum += $vertPosition[$a]; } float $centroidX = $vertPositionSum/$vertCount; if ($centroidX <= 0) { $badFaces[$b] = $face; $b = $b + 1; } } delete $badFaces; select -r $sel[0]; }