Hey,

Thanks for the help! I found an approach that feels a little ugly, but gets
the job done. The function resets the 'first' and 'last' frame knobs on the
input read node to each frame in the sequence that needs to be checked and
gets the corresponding width and height. At the end of the check, the
original 'first' and 'last' values are reset. Changing the node seems
dangerous though. Source is below.

The image sequences can have varying resolution because some frames are
likely to consistent of a single constant value. The application generating
the frame knows this and will shrink constant frames down to small proxy
res frames rather than keeping them at the full resolution.

HP

    # Get the resolution from a read node where the sequence may vary
resolution over time
    def getSequenceResolution(self, readNode, frames):
        varies = False
        if readNode.Class() == 'Read':
            originalFirstFrame = readNode['first'].getValue()
            originalLastFrame = readNode['last'].getValue()

            initialWidth = int(readNode.width())
            initialHeight = int(readNode.height())

            maxWidth = initialWidth
            maxHeight = initialHeight
            for frame in frames:
                readNode['first'].setValue( int(frame) )
                readNode['last'].setValue( int(frame) )

                width = int(readNode.width())
                height = int(readNode.height())
                #print( "\t\t\tframe : %d, width : %d, height : %d" %
(int(frame), width, height) )
                if width > maxWidth:
                    maxWidth = width
                if height > maxHeight:
                    maxHeight = height
                if width != initialWidth or height != initialHeight:
                    varies = True

            #print( "\t\t\tmax width : %d, max height : %d, varies : %s" %
(maxWidth, maxHeight, varies) )

            readNode['first'].setValue( int(originalFirstFrame) )
            readNode['last'].setValue( int(originalLastFrame) )
        else:
            #print( "Not a read node - using normal width and height" )
            maxWidth = readNode.width()
            maxHeight = readNode.height()

        return ( maxWidth, maxHeight, varies )








On Thu, May 8, 2014 at 11:55 PM, Diogo Girondi <diogogiro...@gmail.com>wrote:

> Different resolution or just different data window?
>
> If it's the second you have to get/query its bbox (x, y, r, t).
>
>
> On Thu, May 8, 2014 at 11:00 PM, Erwan Leroy <er...@erwanleroy.com> wrote:
>
>> Unrelated question, but how do you end up with an image with a variable
>> resolution?
>> I've never seen that before. Is it for a specific purpose?
>>
>>
>> On Thu, May 8, 2014 at 4:43 PM, Dan Rosen <danrosenro...@yahoo.com>wrote:
>>
>>> 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
>>>
>>>
>>
>
> _______________________________________________
> 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