Bake object
-
On 25/09/2014 at 15:48, xxxxxxxx wrote:
Is there a way to access / use the Bake Object function in the Timeline using Python?
So, set variables in the Bake Object Dialog and simulate the OK button?c4d.CallCommand(465001219) # Bake Objects...
tool=doc.GetAction()
tool=c4d.plugins.FindPlugin(tool, c4d.PLUGINTYPE_TOOL)will open the dialog, but how proceed?
Also the tool returned is not Bake Object...-Pim
-
On 28/09/2014 at 12:30, xxxxxxxx wrote:
Hi Pim,
doc.GetAction() is the actual tool like e.g.liveselection.
The dialog initializes the next tool, in this case the bake tool, but no action jet.As we discussed, here a small version of the bake tool to begin with.
cheers
Martinimport c4d from c4d import gui,utils ##### monkeytack bake script ##### def SetCTracks(self,pos,rot,scale,pla,animP) : trpX = None trpY = None trpZ = None trrX = None trrY = None trrZ = None trsX = None trsY = None trsZ = None trPLA = None trs = op.GetCTracks() if trs != None: for tr in trs: if tr.GetDescriptionID()[0].id == c4d.ID_BASEOBJECT_POSITION: if tr.GetDescriptionID()[1].id == c4d.VECTOR_X: trpX = tr if tr.GetDescriptionID()[1].id == c4d.VECTOR_Y: trpY = tr if tr.GetDescriptionID()[1].id == c4d.VECTOR_Z: trpZ = tr if tr.GetDescriptionID()[0].id == c4d.ID_BASEOBJECT_ROTATION: if tr.GetDescriptionID()[1].id == c4d.VECTOR_X: trrX = tr if tr.GetDescriptionID()[1].id == c4d.VECTOR_Y: trrY = tr if tr.GetDescriptionID()[1].id == c4d.VECTOR_Z: trrZ = tr if tr.GetDescriptionID()[0].id == c4d.ID_BASEOBJECT_SCALE: if tr.GetDescriptionID()[1].id == c4d.VECTOR_X: trsX = tr if tr.GetDescriptionID()[1].id == c4d.VECTOR_Y: trsY = tr if tr.GetDescriptionID()[1].id == c4d.VECTOR_Z: trsZ = tr if tr.GetDescriptionID()[0].id == c4d.CTpla: trPLA = tr if animP == False: if pos == True and trpX == None: trpX = c4d.CTrack(self, c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION, c4d.DTYPE_VECTOR, 0, ), c4d.DescLevel(c4d.VECTOR_X, c4d.DTYPE_REAL, 0))) self.InsertTrackSorted(trpX) if pos == True and trpY == None: trpY = c4d.CTrack(self, c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION, c4d.DTYPE_VECTOR, 0, ), c4d.DescLevel(c4d.VECTOR_Y, c4d.DTYPE_REAL, 0))) self.InsertTrackSorted(trpY) if pos == True and trpZ == None: trpZ = c4d.CTrack(self, c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION, c4d.DTYPE_VECTOR, 0, ), c4d.DescLevel(c4d.VECTOR_Z, c4d.DTYPE_REAL, 0))) self.InsertTrackSorted(trpZ) if rot == True and trrX == None: trrX = c4d.CTrack(self, c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_ROTATION, c4d.DTYPE_VECTOR, 0, ), c4d.DescLevel(c4d.VECTOR_X, c4d.DTYPE_REAL, 0))) self.InsertTrackSorted(trrX) if rot == True and trrY == None: trrY = c4d.CTrack(self, c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_ROTATION, c4d.DTYPE_VECTOR, 0, ), c4d.DescLevel(c4d.VECTOR_Y, c4d.DTYPE_REAL, 0))) self.InsertTrackSorted(trrY) if rot == True and trrZ == None: trrZ = c4d.CTrack(self, c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_ROTATION, c4d.DTYPE_VECTOR, 0, ), c4d.DescLevel(c4d.VECTOR_Z, c4d.DTYPE_REAL, 0))) self.InsertTrackSorted(trrZ) if scale == True and trsX == None: trsX = c4d.CTrack(self, c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_SCALE, c4d.DTYPE_VECTOR, 0, ), c4d.DescLevel(c4d.VECTOR_X, c4d.DTYPE_REAL, 0))) self.InsertTrackSorted(trsX) if scale == True and trsY == None: trsY = c4d.CTrack(self, c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_SCALE, c4d.DTYPE_VECTOR, 0, ), c4d.DescLevel(c4d.VECTOR_Y, c4d.DTYPE_REAL, 0))) self.InsertTrackSorted(trsY) if scale == True and trsZ == None: trsZ = c4d.CTrack(self, c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_SCALE, c4d.DTYPE_VECTOR, 0, ), c4d.DescLevel(c4d.VECTOR_Z, c4d.DTYPE_REAL, 0))) self.InsertTrackSorted(trsZ) if pla == True and trPLA == None: trPLA = c4d.CTrack(self, c4d.DescID(c4d.DescLevel(c4d.CTpla, c4d.CTpla, 0))) self.InsertTrackSorted(trPLA) trs.append(trPLA) c4d.EventAdd() return trs def SetCurrentFr(FR, doc) : doc.SetTime(c4d.BaseTime(float(FR)/doc.GetFps())) doc.ExecutePasses(None, True, True, True, 0); c4d.GeSyncMessage(c4d.EVMSG_TIMECHANGED) return def BakeObject(obj,doc,fFR,lFR,trs) : time = doc.GetTime() fps = doc.GetFps() #SendModelingCommand container for PLA settings = c4d.BaseContainer() settings.SetBool(c4d.MDATA_CURRENTSTATETOOBJECT_INHERITANCE, True) settings.SetBool(c4d.MDATA_CURRENTSTATETOOBJECT_KEEPANIMATION, True) settings.SetBool(c4d.MDATA_CURRENTSTATETOOBJECT_NOGENERATE,False) for FR in range(fFR,(lFR+1)) : c4d.StatusSetBar(100*(FR-fFR)/(lFR-fFR)) SetCurrentFr(FR, doc) CurrTime = c4d.BaseTime(FR,fps) #bake for tr in trs: curve=tr.GetCurve() val = curve.GetValue(CurrTime, fps) if tr.GetDescriptionID()[0].id == c4d.CTpla: newobjList = utils.SendModelingCommand( command = c4d.MCOMMAND_CURRENTSTATETOOBJECT, list= [obj.GetClone()], mode=c4d.MODELINGCOMMANDMODE_ALL, bc = settings, doc = doc) newObj = newobjList[-1] keyPLA = curve.AddKey(CurrTime)['key'] tr.FillKey(doc,newObj,keyPLA) else: key = curve.AddKey(CurrTime)['key'] key.SetValue(curve, val) #update timeline c4d.GeSyncMessage(c4d.EVMSG_TIMECHANGED) print "object baked" #reset timeline doc.SetTime(time) c4d.EventAdd(c4d.EVENT_ANIMATE) c4d.StatusClear() return def main() : if op==None:return doc = c4d.documents.GetActiveDocument() ######################################### #params fFR = 0 #firstframe lFR = 20 #lastframe allP = True if allP == True: p = True #position r = True #rotation s = True #scale PLA = True #Pointlevel #else set some values animP = True #only animated parameters ######################################### trs = SetCTracks(op,p,r,s,PLA,animP) BakeObject(op,doc,fFR,lFR,trs) c4d.EventAdd() if __name__=='__main__': main()
-
On 29/09/2014 at 00:45, xxxxxxxx wrote:
Great, thank you.
-Pim
-
On 29/09/2014 at 06:50, xxxxxxxx wrote:
you´re welcome.
I guess the baking tool is´nt even a normal tool.
I can´t find something about it in the docs.Anyway there is a lot to do to make it a full version.
Baking expressions , clean up the tracks and make a copy.good luck
Martin