New version info:
Instead of using the mesh's name, select the mesh to mirror before running the script.
You can choose to mirror the X, Y, or Z axis. It defaults to X automatically. For Y and Z, create a string attribute named "Mirror" with a value of "Y" or "Z".
#command("object");
/* X, Y, Z axis mesh mirror, USE AT YOUR OWN RISK */
shape $S, $NewS, $AS[0], $AS2[0];
attribute $Attr, $AxisAttr;
int $i, $j;
point3 $pointedit;
quaternion $rotation;
string $AxisStr;
project.curObject.GetShapes($AS);
for $i = $AS.size-1 to 0 step -1 do {
if ($AS[$i].Selected == 1)
$AS2.push($AS.pop());
else
$AS.pop();
}
if ($AS2.size == 1)
$S = $AS2[0];
if ($S.Selected == 1) {
$Attr = project.curObject.LookupAttribute("STOP");
/* create a copy */
$NewS = mesh();
while ($Attr == NULL) {
$NewS.Open();
/* copy the points and faces */
for $i = 0 to $NewS.GetNumPoints()-1 do {
$NewS.SetPointSelected($i, true);
}
$NewS.DeleteSelectedPoints();
$AxisAttr = project.curObject.LookupAttribute("Mirror");
$AxisStr = $AxisAttr.GetStringValue();
if ($AxisStr != "Y" && $AxisStr != "Z") { /* X axis mirror is default behavior */
/* correct orientaton for X*/
$rotation = $S.orientation;
$rotation.y = -$rotation.y;
$rotation.z = -$rotation.z;
$NewS.orientation = $rotation;
for $i = 0 to $S.GetNumPoints()-1 do {
$pointedit = $S.GetPoint($i);
$pointedit.x = -$pointedit.x; /* mirror around X axis */
$NewS.AddPoint($pointedit);
}
}
if ($AxisStr == "Y") {
/* correct orientaton for Y*/
$rotation = $S.orientation;
$rotation.x = -$rotation.x;
$rotation.z = -$rotation.z;
$NewS.orientation = $rotation;
for $i = 0 to $S.GetNumPoints()-1 do {
$pointedit = $S.GetPoint($i);
$pointedit.y = -$pointedit.y; /* mirror around Y axis */
$NewS.AddPoint($pointedit);
}
}
if ($AxisStr == "Z") {
/* correct orientaton for Z*/
$rotation = $S.orientation;
$rotation.x = -$rotation.x;
$rotation.y = -$rotation.y;
$NewS.orientation = $rotation;
for $i = 0 to $S.GetNumPoints()-1 do {
$pointedit = $S.GetPoint($i);
$pointedit.z = -$pointedit.z; /* mirror around Z axis */
$NewS.AddPoint($pointedit);
}
}
for $i = 0 to $S.GetNumFaces()-1 do {
$NewS.OpenFace(0, 0);
for $j = 0 to $S.GetNumSides($i)-1 do {
$NewS.VertexN($S.GetFacePointIndex($i, $S.GetNumSides($i)-1-$j));
}
$NewS.CloseFace();
}
$NewS.Close();
/* check for attribute to stop the cycle */
$Attr = project.curObject.LookupAttribute("STOP");
}
}