Although there is a cool Magic Center plugin which center axis of a polygon or a spline you may still want to learn how to use that function in order to use on your own projects…

To start our project we need to create a sample spline, it would be text or etc., press C to convert it into an editable spline.

Then we’re going to create a null to apply our xpresso tag. You may add xpresso tag by right clicking on your null and select Cinema 4D Tags – Xpresso.

You should add Bounding Box node, C.O.F.F.E.E. node and your sample spline’s object node (you can simply drag and drop your spline into your xpresso editor.)

Insert “object” output from your spline object node and connect it to Bounding Box’s object port. It will give information about spline’s size which will be necessary on our C.O.F.F.E.E. script.

Now click on your C.O.F.F.E.E. node and add refobjname (Link), boxmin (Vector), boxmax (Vector), boxsize (Vector) input ports. Enter the code below and the code will do rest automatically…

[toggle title=”C.O.F.F.E.E. Script Code” variation=”coffee”]// main() { var doc = GetActiveDocument(); name = refobjname->GetName(); var obj= doc->FindObject(name); // check spline if(!obj->IsInstanceOf(Ospline)) { println (“No point object; exit!”); return; } // Get the current position; box is defined through input vars var pos = obj->GetPosition(); // calculate the relative center var center = boxsize / 2 ; var newpos = boxmin+center; println (“Newpos”,newpos,” = “,boxmax-center); obj->SetPosition(newpos); var correct = newpos-pos; var points=obj->GetPoints(); var np=obj->GetPointCount(); var f,ppos; for(f=np-1;f>=0;f–){ ppos=points[f]; ppos-=correct; points[f]=ppos; count = np; } obj->SetPoints(points); obj->Message(MSG_UPDATE); } [/toggle]

You may download example file;

[wpdm_file id=48]

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.