import time
PT_bef = 0
PT_sum = 0
def PT_Before():
global PT_bef
if nuke.thisGroup()['clear'].value():
nuke.memory("free")
nukescripts.clearAllCaches()
PT_bef = time.time()
def PT_After():
global PT_bef
global PT_sum
tmp = time.time() - PT_bef
PT_sum += tmp
def PT_Run():
node = nuke.thisNode()
if node.input(0) is not None:
if node['clear'].value():
nuke.memory("free")
nukescripts.cache_clear('')
#reset sum variable
global PT_sum
PT_sum = 0
frame = nuke.frame()
samples = node['samples'].value()
sampleRange = []
for i in range(int(samples)):
sampleRange.append(frame)
with node:
writeNode = nuke.toNode('Write1')
nuke.execute(writeNode, nuke.FrameRanges(sampleRange))
average = round(PT_sum/samples, 4)
#create result knob
inputName = node.input(0).name()
textstr = ' %s sec\t\t%s %s\t frame %s' % (str(average), str(int(samples)), 'samples' if samples > 1 else 'sample ', frame)
Knob = nuke.Text_Knob('result', '<b>' + inputName + ':</b>', textstr)
node.addKnob( Knob )
else:
nuke.message('Node has no input!')
def PT_ClearResults():
node = nuke.thisNode()
for i in node.allKnobs():
if i.name() == 'result':
node.removeKnob(i)