mogh
03-01-2010, 07:08 AM
Hi all,
UPDATE: Working Script at the bottom ....
My goal is to make a script which deletes small objects from a sczene.
I managed to copy paste myself a script from PerAnders wonderfull Wiki (http://www.per-anders.net/w/index.php). I guess I am stuck at the point how to get the min value and compare it hence i get tripple values (vector i guess).
the output is e.g.
[260.1234456,90.123456,45.123456]
how do i compeare this with a value ?
i marked the problem zone down in the code
thanks for your help in advance.
here is the script so far
getNextObject(op)
{
if (!op) return null;
if (op->GetDown()) return op->GetDown();
while (!op->GetNext() && op->GetUp()) op = op->GetUp();
return op->GetNext();
}
//Class for finding the bounding box of a set of points
class MinMax
{
var min;
var max;
public:
Init();
AddPoint(p);
GetMin();
GetMax();
GetMp();
GetRad();
GetSize();
}
MinMax::Init()
{
min = vector(MAXREAL);
max = vector(MINREAL);
}
MinMax::AddPoint(p)
{
if (p.x < min.x) min.x = p.x;
if (p.x > max.x) max.x = p.x;
if (p.y < min.y) min.y = p.y;
if (p.y > max.y) max.y = p.y;
if (p.z < min.z) min.z = p.z;
if (p.z > max.z) max.z = p.z;
}
MinMax::GetMin()
{
return min;
}
MinMax::GetMax()
{
return max;
}
MinMax::GetMp()
{
return (min + max) * 0.5;
}
MinMax::GetRad()
{
return (max - min) * 0.5;
}
MinMax::GetSize()
{
return (max - min);
}
//------------------------------------
// Function for Getting the size of an object
class GetSize
{
var bb;
public:
Init(op, global); //Object, Bool. Return bool
GetBounds(); //Return Bounding box
}
GetSize::Init(op, global)
{
if (!op || !op->IsInstanceOf(Opoint)) return false;
bb = new(MinMax);
if (!bb) return false;
bb->Init();
var padr = op->GetPoints();
var pcnt = op->GetPointCount();
var i;
if (global)
{
var mg = op->GetMg();
for (i = pcnt - 1; i >= 0 ; --i)
{
bb->AddPoint(mg->GetMulP(padr[i]));
}
}
else
{
for (i = pcnt - 1; i >= 0 ; --i)
{
bb->AddPoint(padr[i]);
}
}
return true;
}
GetSize::GetBounds()
{
return bb;
}
main(doc, op)
{
//Get the first object in the document
var myobject = doc->GetFirstObject();
if (!myobject) return false;
while (myobject)
{
//Do something to "myobject" here
var cl = new(GetSize);
//Get the objects size in global space, for local set second argument to false
if (!cl || !cl->Init(myobject, true)) return false;
// println("Object Scale");
// println(myobject->GetScale());
var bb = cl->GetBounds();
if (!bb) return false;
// println("Object Size and Bounds");
// print("Min :: ");
// println(bb->GetMin());
// print("Max :: ");
// println(bb->GetMax());
print("Radius :: ");
println(bb->GetRad());
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// what to do here ????
if (bb->GetRad() <= 150 ){
println ("Object to small delete me");
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// print("Size :: ");
// println(bb->GetSize());
// print("Mid Point :: ");
// println(bb->GetMp());
myobject = getNextObject(myobject);
}
return true;
}
UPDATE: Working Script at the bottom ....
My goal is to make a script which deletes small objects from a sczene.
I managed to copy paste myself a script from PerAnders wonderfull Wiki (http://www.per-anders.net/w/index.php). I guess I am stuck at the point how to get the min value and compare it hence i get tripple values (vector i guess).
the output is e.g.
[260.1234456,90.123456,45.123456]
how do i compeare this with a value ?
i marked the problem zone down in the code
thanks for your help in advance.
here is the script so far
getNextObject(op)
{
if (!op) return null;
if (op->GetDown()) return op->GetDown();
while (!op->GetNext() && op->GetUp()) op = op->GetUp();
return op->GetNext();
}
//Class for finding the bounding box of a set of points
class MinMax
{
var min;
var max;
public:
Init();
AddPoint(p);
GetMin();
GetMax();
GetMp();
GetRad();
GetSize();
}
MinMax::Init()
{
min = vector(MAXREAL);
max = vector(MINREAL);
}
MinMax::AddPoint(p)
{
if (p.x < min.x) min.x = p.x;
if (p.x > max.x) max.x = p.x;
if (p.y < min.y) min.y = p.y;
if (p.y > max.y) max.y = p.y;
if (p.z < min.z) min.z = p.z;
if (p.z > max.z) max.z = p.z;
}
MinMax::GetMin()
{
return min;
}
MinMax::GetMax()
{
return max;
}
MinMax::GetMp()
{
return (min + max) * 0.5;
}
MinMax::GetRad()
{
return (max - min) * 0.5;
}
MinMax::GetSize()
{
return (max - min);
}
//------------------------------------
// Function for Getting the size of an object
class GetSize
{
var bb;
public:
Init(op, global); //Object, Bool. Return bool
GetBounds(); //Return Bounding box
}
GetSize::Init(op, global)
{
if (!op || !op->IsInstanceOf(Opoint)) return false;
bb = new(MinMax);
if (!bb) return false;
bb->Init();
var padr = op->GetPoints();
var pcnt = op->GetPointCount();
var i;
if (global)
{
var mg = op->GetMg();
for (i = pcnt - 1; i >= 0 ; --i)
{
bb->AddPoint(mg->GetMulP(padr[i]));
}
}
else
{
for (i = pcnt - 1; i >= 0 ; --i)
{
bb->AddPoint(padr[i]);
}
}
return true;
}
GetSize::GetBounds()
{
return bb;
}
main(doc, op)
{
//Get the first object in the document
var myobject = doc->GetFirstObject();
if (!myobject) return false;
while (myobject)
{
//Do something to "myobject" here
var cl = new(GetSize);
//Get the objects size in global space, for local set second argument to false
if (!cl || !cl->Init(myobject, true)) return false;
// println("Object Scale");
// println(myobject->GetScale());
var bb = cl->GetBounds();
if (!bb) return false;
// println("Object Size and Bounds");
// print("Min :: ");
// println(bb->GetMin());
// print("Max :: ");
// println(bb->GetMax());
print("Radius :: ");
println(bb->GetRad());
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// what to do here ????
if (bb->GetRad() <= 150 ){
println ("Object to small delete me");
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// print("Size :: ");
// println(bb->GetSize());
// print("Mid Point :: ");
// println(bb->GetMp());
myobject = getNextObject(myobject);
}
return true;
}
