Try this threading technique. there's a sleep in there to give time for
Nuke to evaluate.

import threading
import time

def doIT():

    nukeNode = nuke.selectedNode()

    firstFrame = int(nuke.Root()['first_frame'].getValue())
    lastFrame = int(nuke.Root()['last_frame'].getValue())
    totalFrames = lastFrame - firstFrame
    print( firstFrame, lastFrame )

    #toggle frame to initiate getting the correct value
    current_frame = nuke.frame()
    nuke.frame( current_frame -1 )
    nuke.frame( current_frame )

    width = nukeNode.width()
    height = nukeNode.height()

    maxWidth = 0
    maxHeight = 0

    task = nuke.ProgressTask('Getting width and height in range ' +
str(firstFrame) + ' ' + str(lastFrame))

    progIncr = 100.0 / totalFrames

    for frame in range(firstFrame, lastFrame+1):
        if task.isCancelled():
            nuke.executeInMainThread(nuke.message, args=('Aborted',))
            return

        nuke.frame( frame )
        #Giving time for Nuke to evaluate
        time.sleep(.1)

        width = nukeNode.width()
        height = nukeNode.height()

        task.setProgress(int(frame * progIncr))
        task.setMessage( str(frame) + ' '  + str(width) + ' ' + str(height)
)

        if width > maxWidth:
            maxWidth = width
        if height > maxHeight:
            maxHeight = height

        print (frame, width, height)

    print( maxWidth, maxHeight )
    nuke.frame( current_frame )

threading.Thread(target=doIT).start()



On Thu, May 8, 2014 at 12:22 PM, Haarm-Pieter Duiker <
l...@duikerresearch.com> wrote:

> Hi,
>
> Simple question. Is there a way to query the width and height of a node at
> different times?
>
> Here's the context.
> I'm working with data sets that include image sequences that vary
> resolution from frame to frame. I'd like to find the max width and height
> for a given image in a given frame range. I wrote the following code to
> test things out.
>
> nukeNode = nuke.selectedNode()
>
>
> firstFrame = int(nuke.Root()['first_frame'].getValue())
>
> lastFrame = int(nuke.Root()['last_frame'].getValue())
>
> print( firstFrame, lastFrame )
>
>
> maxWidth = 0
>
> maxHeight = 0
>
> for frame in range(firstFrame, lastFrame):
>
>     nuke.frame( frame )
>
>     width = nukeNode.width()
>
>     height = nukeNode.height()
>
>     print( frame, width, height )
>
>     if width > maxWidth:
>
>         maxWidth = width
>
>     if height > maxHeight:
>
>         maxHeight = height
>
>
> print( maxWidth, maxHeight )
>
>
> The width and height values don't update to reflect the value for the
> current frame. This seems to parallel the functionality of the Knob
> getValue vs. getValueAt functions. Since width and height aren't knobs,
> those functions don't help though.
>
>
> Is there a way to query the width and height of a node at different times,
> like the Knob getValueAt method?
>
>
> HP
>
>
>
>
>
>
> _______________________________________________
> Nuke-python mailing list
> Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/
> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>
>
_______________________________________________
Nuke-python mailing list
Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python

Reply via email to