On 27/11/2014 at 03:45, xxxxxxxx wrote:
Hi guys,
I just moved from 3ds max to c4d and so I m moving from maxscript to python at the same time.
I am trying to write a script to automate baking on selected object, to be more specific creating a null and matching his position/rotation/scale to the object and keying the null on every frame.
In maxscript I would have done a for loop looking like that (baking the object named 'objectToBake' for a 250 frames long scene) :
------------------------------------
target=$objectToBake
obj=point() //create null
for i=0 to 250 do
(
sliderTime = i
obj.transform=target.transform
obj.addkey (this won t be that line but it s just the concept)
)
------------------------------------
Then in c4d I did the same thing in python. So within the object to bake selected I run this:
------------------------------------
import c4d
from c4d import gui
#Welcome to the world of Python
scene_fps=doc[c4d.DOCUMENT_FPS]
sceneStart=doc[c4d.DOCUMENT_MINTIME]
sceneEnd=doc[c4d.DOCUMENT_MAXTIME]
obj=c4d.BaseObject(5140)
doc.InsertObject(obj)
target=doc.GetActiveObject()
posTrack=obj.FindCTrack(c4d.ID_BASEOBJECT_REL_POSITION)
if not posTrack:
posTrack=c4d.CTrack(obj,c4d.ID_BASEOBJECT_REL_POSITION)
obj.InsertTrackSorted(posTrack)
curve=posTrack.GetCurve()
for i in range(0,91) :
doc[c4d.DOCUMENT_TIME]=c4d.BaseTime(i,scene_fps)
newPos=target[c4d.ID_BASEOBJECT_REL_POSITION]
obj[c4d.ID_BASEOBJECT_REL_POSITION]=newPos
keySet=curve.AddKey(c4d.BaseTime(i,scene_fps))
posTrack.FillKey(doc,obj,keySet["key"])
c4d.EventAdd() // here is my issue, can t update during a loop
----------------------------------------
And basically it works only on the first frame.
From what I read it s all because script in c4d are singlethread and so the positions don t update during the loop even though I update the time slider position during the loop.
So now I m trying to do it through a plugin hoping now my positions will be updated during the loop.
Is a plugin the good way to do it ?
I also want to create an user inteface to select the objects I want to bake and all that stuff. And then I was wondering if this go with the plugin as well and if a plugin is the only way to do it.
Hope all this is not to confusing but I m a bit lost with what script are doing and what plugins are for in c4d.
Would be great if you can let me know if I m in the good direction or not.
To make it very simple, I just want to know what is the way to run commands in a loop and having everything updated at each loop iteration.
Thank you !