hello,
Something like this maybe. I needed to create my own "insertLast" function because the GeListHead was not alive in the new document.
But i don't build my scene with dynamics, could you send us your scene at [email protected] ?
sorry for the small amount of comment.
import c4d
from c4d import gui
import os
# Welcome to the world of Python
def GetLast(doc):
# retrieves the last element of the document
child = doc.GetFirstObject()
if child is None:
return None
while child:
if child.GetNext() is None:
return child
child = child.GetNext()
def InsertLast(doc, op):
# Insert object after the last object in the scene.
last = GetLast(doc)
if last is None:
# that mean this is the first element added in the scene
doc.InsertObject(op)
else:
op.InsertAfter(last)
def CSTO(op, keepAnimation = False ):
# Current state to object.
# the Keep animation will be set in the basecontainer for the command
doc = op.GetDocument()
# send the modeling command
bc = c4d.BaseContainer()
bc.SetBool(c4d.MDATA_CURRENTSTATETOOBJECT_KEEPANIMATION, keepAnimation)
res = c4d.utils.SendModelingCommand(command = c4d.MCOMMAND_CURRENTSTATETOOBJECT,
list = [op],
mode = c4d.MODELINGCOMMANDMODE_ALL,
bc = bc,
doc = doc)
# Cheks if the command didn't failed
if res is False:
raise TypeError("return value of CSTO is not valie")
# Returns the first object of the list.
return res[0]
def GetNextObject(doc):
# get he next object in the scene, only the first level of hierarchy is used.
op = doc.GetFirstObject()
while op:
yield op
op=op.GetNext()
def MyPolygonize(doc, keepAnimation = False):
# For each first level element, call a CSTO and store the result in a new document
dst = c4d.documents.BaseDocument()
if dst is None:
raise ValueError("can't create a new document")
for op in GetNextObject(doc):
res = CSTO(op, keepAnimation)
InsertLast(dst, res)
return dst
def main():
file_path = doc.GetDocumentPath()
file_oriname = doc.GetDocumentName()[:-3] #remove .c4d
dst = None
for i in xrange(10):
# Update the document's time
doc.SetTime(c4d.BaseTime(i, doc.GetFps()))
# Updates timeline
c4d.GeSyncMessage(c4d.EVMSG_TIMECHANGED)
# Sometimes you must execute this twice to be sure cache is built.
# Using the flag BUILDFLAGS_INTERNALRENDERER will allow to have the voronoi fracture cache to be calculated
doc.ExecutePasses(None, True, True, True, c4d.BUILDFLAGS_INTERNALRENDERER)
currentFrame = doc.GetTime().GetFrame(doc.GetFps())
# Export the C4D file
file_name = os.path.join(file_path,file_oriname + str(currentFrame) + ".c4d")
dst = MyPolygonize(doc, False)
if dst is not None:
c4d.documents.SaveDocument(dst,file_name,c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST | c4d.SAVEDOCUMENTFLAGS_SAVECACHES,c4d.FORMAT_C4DEXPORT)
# Execute main()
if __name__=='__main__':
main()
Cheers,
Manuel