简体   繁体   中英

Caching a script using NUKE API

I want to write a script that uses Nuke's built-in Performance Timers to "sanity-check" the current comp. For this I am clearing all of the viewer cache to start off fresh. Now I need to trigger the caching. As it seems the only way to achieve this is by using nuke.activeViewer().play(1) . Using this call I get my timeline cached but I have no indication of when the timeline is fully cached to be able to stop and reset the Performace Timers.

I am aware that I can also use nuke.activeViewer().frameControl(+1) to skip 1 frame at a time till I'm at the last frame but it seems to me that using this call is not causing the comp to cache that frame. Actually the timeline indicates that the frame is cached but nuke.activeViewer().node().frameCached(nuke.frame()) is returning false .

Nevertheless I have written something that is working but only really barely.

Here it is:

import nuke

nuke.clearRAMCache()

vc = nuke.activeViewer()
v = vc.node()
fr = v.playbackRange()

vc.frameControl(-6)

print fr.maxFrame()

cached_frames = 0
while cached_frames < fr.maxFrame():
    print "Current Frame: {}".format(nuke.frame())

    if not v.frameCached(nuke.frame()):
        print "Frame: {} not cached".format(nuke.frame())

        while not v.frameCached(nuke.frame()):
             print "caching..."
             vc.play(1)
        print "Frame: {} cached".format(nuke.frame())
        print "Incrementing from caching"
        cached_frames += 1
    else:
        vc.frameControl(1)
        print "incrementing from skipping"
        #cached_frames += 1
    print "Cached Frames: {}".format(cached_frames)

print "DONE"
vc.stop()

I know that this is not a really nice piece of code but sometimes these lines execute really well and at other times it just hangs a random (at least it seems so) amount of time.

So are there any callbacks available or writable for the Viewer in Nuke or something similar?

Any help is much appreciated!

What specific requirement wrt performance do you want to achieve ?

Nuke has its built in feature

"Nuke can display accurate performance timing data onscreen or output it to XML file to help you troubleshoot bottlenecks in slow scripts. When performance timing is enabled, timing information is displayed in the Node Graph, and the nodes themselves are colored according to the proportion of the total processing time spent in each one, from green (fast nodes) through to red (slow nodes)." -

referred to

Mimicking callbacks on the viewer timeline is only achievable using Threads. Just create a Thread, check for the current frame to be cached and step to the next frame using nuke.activeViewer().frameControl() from that Thread.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM