Set Axis to Center via Python
-
On 22/06/2015 at 03:59, xxxxxxxx wrote:
Hello,
I would like to set axis to center of an object. And as I will use it in xpresso-python node, it should only fire for once. Position will be 0,0,0. I tried script below, please help.import c4d
from c4d import Vector as vdef setAxis(obj) :
size = obj.GetRad()
position = obj.GetMp() + obj.GetAbsPos()
if obj is None or not obj.CheckType(c4d.Opoint) : return False
oldm = obj.GetMg()
points = obj.GetAllPoints()
pcount = obj.GetPointCount()
doc.StartUndo()
doc.AddUndo(c4d.UNDOTYPE_CHANGE, obj)
obj.SetAbsRot(v(0))
obj.SetAbsPos(v(0))
obj.Message(c4d.MSG_UPDATE)
newm = obj.GetMg()
newm.off = position-size/2
newm.v1 = newm.v1.GetNormalized()
newm.v2 = newm.v2.GetNormalized()
newm.v3 = newm.v3.GetNormalized()
for p in xrange(pcount) :
obj.SetPoint(p,newm*oldm*points
)
c4d.EventAdd()
obj.Message(c4d.MSG_UPDATE)
c4d.EventAdd()
doc.EndUndo()def main() :
global Source
if Source.CheckType(c4d.Opoint) :
setAxis(Source) -
On 29/06/2015 at 02:38, xxxxxxxx wrote:
Hello,
is this thread on the same topic as in your other thread?
- Center Axis with Python
if so, please avoid double posts.
If you want to execute a python script only once you can edit and execute a script from the Script Manager. This allows you to run scripts that can edit the scene and it's objects as desired.
A Python Xpresso Node should only be used for logic operations etc. and not to edit the current scene since the node will be executed many times.
Best wishes,
Sebastian - Center Axis with Python
-
On 03/07/2015 at 09:40, xxxxxxxx wrote:
Hello grasycho,
was your question answered?
Best wishes,
Sebastian