Hi all!
I am looking for some help in improving a Python Script.
The following script steps through 100 Frames and at the end displays a Score of how long it took to step through all of the Frames (Kind of like a Benchmark)
I would like the Viewport, though, to refresh when stepping through the Frames. Right now it stays frozen until the script is finished. Is there a way to do this?
Thx!
Here is the Scene File: https://www.cgdirector.com/downloads/[cgdirector.com]_c4dViewportBenchmark_v1.0.c4d
Here is the script:
import c4d
import time
from c4d import gui
def message(msg_type, data):
if msg_type == c4d.MSG_NOTIFY_EVENT:
event_data = data['event_data']
if event_data['msg_id'] == c4d.MSG_DESCRIPTION_COMMAND:
desc_id = event_data['msg_data']['id']
print desc_id
if desc_id[1].id == 1:
print "Running Benchmark..."
runbenchmark()
def runbenchmark() :
# 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
newtime = c4d.BaseTime(frame, fps)
doc.SetTime(newtime)
# Animate document at current frame
doc.ExecutePasses(None, True, True, True, c4d.BUILDFLAGS_INTERNALRENDERER)
c4d.EventAdd()
currentFrame = doc.GetTime().GetFrame(doc.GetFps())
#print currentFrame
global start, end, score
if currentFrame == 1:
start = time.time()
if currentFrame >= 5 and currentFrame <= 99:
end = time.time()
score = currentFrame/(end - start)
if currentFrame == 100:
scoreRounded = round(score*100,2)
textOutput = "[cgdirector.com] [v1.0] Your C4D Viewport Benchmark Score: %s" % (scoreRounded)
print textOutput
guid = gui.MessageDialog(textOutput)
# Restore to original time
doc.SetTime(originalTime)
doc.ExecutePasses(None, True, True, True, c4d.BUILDFLAGS_INTERNALRENDERER)
c4d.EventAdd()
def main():
obj = op.GetObject()
bc = c4d.BaseContainer()
obj.AddEventNotification(op, c4d.NOTIFY_EVENT_MESSAGE, 0, bc)