Search code examples
pythonnuke

How to update nuke.frame() value in NUKE via Python?


I want to automatically play and stop the sequence in The Foundry NUKE using if...else conditional statements. I can easily start playing the sequence but I can't stop it. The problem is a value nuke.frame() doesn't update. If someone has any experience on this issue, please help me.

Here's a code:

checker = nuke.createNode('CheckerBoard2', 'boxsize 100 centerlinewidth 0')
blur = nuke.createNode('Blur', 'size sin(frame/10)*25', inpanel=False)
merge = nuke.createNode('Merge2', inpanel=False)
wheel = nuke.createNode("ColorWheel", 'rotate frame*10 centerSaturation 1')
merge.connectInput(0, wheel)
nuke.toNode('Merge1').setSelected(True)
nukescripts.connect_selected_to_viewer(0)

for all in nuke.allNodes():
    all.setSelected(True)
_autoplace()

f = nuke.frame(1)

def playBlast():
    if f >= 1 and f <= 99:
        nuke.activeViewer().play(1)
        return        
    else:
        nuke.activeViewer().stop()
        print f

playBlast()

Solution

  • I've found a solution for my problem:

    def playBlast():
        for time in range(1, 201, 1):
            if nuke.frame(time) >= 1 and nuke.frame(time) <= 99:
                nuke.activeViewer().play(1)
            else: 
                nuke.activeViewer().stop() 
    
    playBlast()