THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/11/2006 at 04:58, xxxxxxxx wrote:
User Information:
Cinema 4D Version:
Platform: Mac ;
Language(s) : C.O.F.F.E.E ;
---------
subject : center axes (of all polygon objects in document)
i have to do this often because i do import a lot of files
and sometimes all axis centers are at (0,0,0) instead of
being in the centers of the objects.
i got the base script somewhere else, and added the code
to process the full hierarchy of the document to find all
polygon objects.
help needed : this script has a problem with hierarchies!
-
generate 3 cubes, convert them to polygon objects and
drop them on each other so that the second is the firsts
child and the third is the seconds child.
-> use the object axis tool to move the first cubes axis
a little bit off center, then start the script.
you'll see the misbehaviour, by reseting the axis center
of the first object the childs move!
i could not find the way to correct this, and would be
very happy about a little help ! :)
thanks for any reply!
zeo
ps. see console output to have some debug info :)
center_axes(obj);
main(doc,op)
{
println (" ");
println ("CenterAllAxes 0.6");
var doc=GetActiveDocument();
var obj=doc->GetFirstObject();
var count_all=0, count_done=0, level=0;
while(obj)
{
print ("- "); var j; for(j=0;j<level;j++) { print(" "); }
println (obj->GetName(), " (", obj->GetType(), ")");
count_all++;
if(obj->GetType()==5100) { center_axes(obj); count_done++; }
if(obj->GetDown()) { obj=obj->GetDown(); level++; continue; }
while(! obj->GetNext() && level>0) { obj=obj->GetUp(); level--; }
obj=obj->GetNext();
}
println (count_all," objects processed, ", count_done, " axes centered.");
}
center_axes(obj)
{
var i, sumV=vector(0);
var matG=obj->GetMg(), matG_neu=new(Matrix);
var punkte=obj->GetPoints();
var anzahl=obj->GetPointCount();
var y_min = punkte[0].y, y_max = punkte[0].y;
if(anzahl==0) return false;
for(i=0; i<anzahl; i++) { sumV+=matG->GetMulP(punkte _); }
sumV/=anzahl;
/*
// optional code to set the center to the bottom of the object
for(i=0; i<anzahl; i++) {
if(y_min > punkte _.y) { y_min = punkte _.y; }
if(y_max < punkte _.y) { y_max = punkte _.y; }
}
sumV.y = y_min;
*/
matG_neu->SetV1(matG->GetV1());
matG_neu->SetV2(matG->GetV2());
matG_neu->SetV3(matG->GetV3());
matG_neu->SetV0(sumV);
obj->SetMg(matG_neu);
matG_neu->Invert();
for(i=0; i<anzahl; i++) { punkte _=matG_neu- >GetMulP(matG->GetMulP(punkte _)); }
obj->SetPoints(punkte);
obj->Message(MSG_UPDATE);
}