I put this small jscript together yesterday.
I know it is very crude but it works for me, maybe someone else will find it useful...
Code:
var fso = new ActiveXObject("Scripting.FileSystemObject");
var wss = new ActiveXObject("WScript.Shell");
var buffer = "";
var Polygones = new Array();
var polyIndex = 0;
var inputFilename = "write_filename_here.ac";
var outputFilename = fso.GetBaseName(inputFilename) + ".txt";
var input = fso.OpenTextFile(inputFilename, 1);
while (!input.AtEndOfStream)
{
var tokens = GetTokens();
switch (tokens[0])
{
case "OBJECT":
if (tokens[1] == "poly")
{
var name = "noname";
tokens = GetTokens();
if (tokens[0] == "name")
{
name = tokens[1];
}
var p = new Polygon(name);
Polygones[polyIndex] = p;
}
break;
case "numvert":
var p = Polygones[polyIndex];
for (var i=0; i < 8; i++)
{
p.SetCoordinates(GetTokens());
}
p.CalcDimensions();
polyIndex++;
break;
}
}
input.Close();
Polygones.sort(CompareForPolygons);
PrintBOM();
wss.Popup(buffer, 0, "AC3D Bill of Material");
function Polygon(name)
{
this.name = name;
this.xs = new Array(8);
this.ys = new Array(8);
this.zs = new Array(8);
this.xyzIndex = 0;
this.dimensions = new Array(3);
this.SetCoordinates = setCoordinates;
this.CalcDimensions = calcDimensions;
}
function setCoordinates(tokens)
{
this.xs[this.xyzIndex] = tokens[0];
this.ys[this.xyzIndex] = tokens[1];
this.zs[this.xyzIndex] = tokens[2];
this.xyzIndex++;
}
function calcDimensions()
{
var minX = Math.min(this.xs[0], this.xs[1], this.xs[2], this.xs[3], this.xs[4], this.xs[5], this.xs[6], this.xs[7]);
var maxX = Math.max(this.xs[0], this.xs[1], this.xs[2], this.xs[3], this.xs[4], this.xs[5], this.xs[6], this.xs[7]);
var minY = Math.min(this.ys[0], this.ys[1], this.ys[2], this.ys[3], this.ys[4], this.ys[5], this.ys[6], this.ys[7]);
var maxY = Math.max(this.ys[0], this.ys[1], this.ys[2], this.ys[3], this.ys[4], this.ys[5], this.ys[6], this.ys[7]);
var minZ = Math.min(this.zs[0], this.zs[1], this.zs[2], this.zs[3], this.zs[4], this.zs[5], this.zs[6], this.zs[7]);
var maxZ = Math.max(this.zs[0], this.zs[1], this.zs[2], this.zs[3], this.zs[4], this.zs[5], this.zs[6], this.zs[7]);
this.dimensions[0] = maxX - minX;
this.dimensions[1] = maxY - minY;
this.dimensions[2] = maxZ - minZ;
this.dimensions.sort(CompareForDimensions);
}
function CompareForDimensions(param1, param2)
{
var first = parseFloat(param1);
var second = parseFloat(param2);
if (first == second)
return 0;
if (first < second)
return -1;
else
return 1;
}
function CompareForPolygons(param1, param2)
{
var result = 0;
var firstD1 = parseFloat(param1.dimensions[0]);
var firstD2 = parseFloat(param1.dimensions[1]);
var secondD1 = parseFloat(param2.dimensions[0]);
var secondD2 = parseFloat(param2.dimensions[1]);
if ((firstD1 == secondD1) && (firstD2 == secondD2))
result = 0;
if ((firstD1 < secondD1) || ((firstD1 == secondD1) && (firstD2 < secondD2)))
result = -1;
if ((firstD1 > secondD1) || ((firstD1 == secondD1) && (firstD2 > secondD2)))
result = 1;
return result;
}
function GetTokens()
{
var textLine = input.ReadLine();
return textLine.split(" ");
}
function print(Data)
{
buffer += Data + "\n";
}
function PrintBOM()
{
var output = fso.CreateTextFile(outputFilename, true);
for (i = 0; i < polyIndex; i++)
{
var txt = Polygones[i].name + " : " + Polygones[i].dimensions[0].toFixed(2) + " x " + Polygones[i].dimensions[1].toFixed(2) + " x " + Polygones[i].dimensions[2].toFixed(2);
print(txt);
output.WriteLine(txt);
}
output.Close();
}