On 05/12/2017 at 03:09, xxxxxxxx wrote:
Hi,
As gr4ph0s already explained, a tag/expression is not the recommended place to process information from the scene and write a file.
About evaluating each frame of a scene manually, using BaseDocument.SetTime()/ExecutePasses() is the way to go from a script or CommandData plugin.
The following script loops through each frame of the active document and prints the position of the active object:
import c4d
def main() :
# Backup original time
originalTime = doc.GetTime()
# Loop through all frames of active document
fps = doc.GetFps()
minFrame = doc.GetMinTime().GetFrame(fps)
maxFrame = doc.GetMaxTime().GetFrame(fps)
for frame in xrange(minFrame, maxFrame+1) :
# Set current frame
time = c4d.BaseTime(frame, fps)
doc.SetTime(time)
# Animate document at current frame
doc.ExecutePasses(None, True, True, True, c4d.BUILDFLAGS_INTERNALRENDERER)
# Print active object position at current frame
if op is not None:
pos = op.GetMg().off
print("Frame " + str(frame) + " Active Object Position: " + str(pos.x) + ", " + str(pos.y) + ", " + str(pos.z))
c4d.EventAdd()
# Restore to original time
doc.SetTime(originalTime)
doc.ExecutePasses(None, True, True, True, c4d.BUILDFLAGS_INTERNALRENDERER)
c4d.EventAdd()
if __name__=='__main__':
main()
The code in main() can be easily transferred to a CommandData.Execute().