Neirao,
Below is your code with the changes you requested:
/*
*Name: Aling points to (x,y,z)
*CopyLeft: 2010
*Author: Neirão
*Date: 03/03/10
*Description: based in Vytautas_alinhar_pontos_line_points_v1
*Parameters: *= width; *= height; *= width_divisions; *= height_divisions;
*/
/***** Init *****/
#command("object");
object $object;
shape $shapes[0];
shape $shape;
int $shape_count;
point3 $points[0];
point3 $point;
int $point_count;
int $i;
int $j;
int $direction;
/* added by NickE */
point3 $sel_max,$sel_min,$sel_center;
/* end of added by NickE */
if (GUI.Xenabled) $direction = 0;
else if (GUI.Yenabled) $direction = 1;
else $direction = 2;
if (GUI.Xenabled && GUI.Yenabled && GUI.Zenabled) $direction = 3;
meshdata $mesh_data;
$object = project.curObject;
$shape_count = $object.GetShapes($shapes);
/*** Get all selected points from all the shapes ***/
for $i = 0 to $shape_count - 1 do{
$shape = $shapes[$i];
/* If shape is a mesh.. */
if($shape.GetKind() == SHAPE_KIND_MESH){
/* i try this..but dont work.. :( --> || $shape.GetKind() == SHAPE_KIND_SUBDIVISION */
/* Get the shape point number */
$point_count = $shape.GetNumPoints();
/* added by NickE */
$sel_max=(-10000,-10000,-10000);
$sel_min=( 10000, 10000, 10000);
for $j = 0 to $point_count - 1 do
{
if ($shape.GetPointSelected($j))
{
$point = $shape.GetPoint($j);
if ($point.x > $sel_max.x) $sel_max.x = $point.x;
if ($point.y > $sel_max.y) $sel_max.y = $point.y;
if ($point.z > $sel_max.z) $sel_max.z = $point.z;
if ($point.x < $sel_min.x) $sel_min.x = $point.x;
if ($point.y < $sel_min.y) $sel_min.y = $point.y;
if ($point.z < $sel_min.z) $sel_min.z = $point.z;
}
}
$sel_center.x=($sel_max.x + $sel_min.x)/2.0;
$sel_center.y=($sel_max.y + $sel_min.y)/2.0;
$sel_center.z=($sel_max.z + $sel_min.z)/2.0;
/* End of added by Nick E */
for $j = 0 to $point_count - 1 do{
if($shape.GetPointSelected($j)) {
$point = $shape.GetPoint($j);
if($direction == 0){
/* $point.x = 0; */
$point.x = $sel_center.x; /* Added by NickE */
}
if($direction == 1){
/* $point.y = 0; */
$point.y = $sel_center.y; /* Added by NickE */
}
if($direction == 2){
/* $point.z = 0; */
$point.z = $sel_center.z; /* Added by NickE */
}
/* TODOS XYZ ATIVADOS alinha todos para */
if($direction == 3){
$point.x = 0;
$point.y = 0;
$point.z = 0;
}
$shape.SetPoint($j, $point);
}
}
}
}
Some things to think about:
1) Do you really want the center, or do you really want the average?
2) This script works on the actual coordinates of the points, so if a mesh is moved or rotated, it still operating on the underlying point coordinates rather than the transformed coordinates. This may give different results than what is expected.