Hi! Welcome! :) Here is the latest version of my script, it should work with expressions, we also use that often. It is used just selecting the readnodes and executing the script. We use it many times so it is tied to a hotkey, I think this is better than having buttons on each node.
Hope it helps Gabor On Wed, Feb 8, 2017 at 2:35 AM, Michael Hodges <[email protected]> wrote: > > I’ve begun to answer my own question and I think I’m pretty close on this. > > I’ve started to adapt a script I found from Gabor Toth (thanks Gabor!) and > hopefully this will help others as well. > > I put a python button on the read node that contains the script below > which replaces the frame ranges correctly. > > The reason I used a button is that it was an easy way to see if it would > work, and two, I couldn’t really figure out how to configure the command to > the specific node on demand. > > > > Three questions: > > 1. Is a button the a good way to achieve this? I thought it might be > best to have it hardwired on the node as it will be buried in one or more > gizmos (that may be created procedurally) and I didn’t trust my Python > chops to isolate it from the other read nodes in the script > > > 2. Assuming that this is the best approach how would I activate the > button press from another node? > > > 3. Since the “file” value is generated by an expression ( in my case: > [value Controller.ClipPath] the real path isn’t being resolved to the > script and fails. It does work as expected with a text path. Would a > different expression technique work or do I have to create some additional > python magic? > > > > Thanks! > > > Michael > > > > ################ > > import nuke > import os > import os.path > import math > import glob > import re > > n = nuke.thisNode() > > > seqPath = n.knob('file').value() > if seqPath is not None and re.match('.*\.%0.*', seqPath): > indx = seqPath.find('%0') > pattern = '%0' + seqPath[indx + 2] + 'd' > seqPathMask = seqPath.replace(pattern, '*') > print '' > print 'PathMask: %s' % (seqPathMask) > seqDir = os.path.dirname(seqPath) > print 'Directory: %s' % (seqDir) > if os.path.exists(seqDir): > files = os.listdir(seqDir) > #print files > > #sorting files > filteredFiles = glob.glob(seqPathMask) > filteredFiles.sort() > if len(filteredFiles) != 0: > (firstFileName, ext) = os.path.splitext( > filteredFiles[0]) > firstFileTags = firstFileName.split('.') > > sfs = firstFileTags[-1] > print 'Extension: ' + ext > sf = int (sfs) # converted to int > print "Start frame: %s" % (sf) > > (lastFileName, ext) = os.path.splitext( > filteredFiles[len(filteredFiles)-1]) > lastFileTags = lastFileName.split('.') > efs = lastFileTags[-1] > ef = int (efs) > print "End frame: %s" % (ef) > > n.knob('first').setValue(sf) > n.knob('last').setValue(ef) > else: > print 'No matching files in this directory! > Skipping...' > else: > print 'Warning! Directory doesnt exist: ' + seqDir > else: > pass > > > > > > > On Feb 7, 2017, at 11:16 AM, Michael Hodges <[email protected]> > wrote: > > > > Is there a way to detect/update the frame range of an image sequence ( > Example_File.#####.dpx) in a read node? > > > > I’ve got some expressions that can change the input file within a gizmo > read node but then I’m stuck with the previous file’s values. I understand > that this may be end up having to be a some sort of python file-counting > callback but I want to check first if there is a way of doing it within > Nuke. > > > > > > Thanks, > > > > Michael_______________________________________________ > > Nuke-users mailing list > > [email protected], http://forums.thefoundry.co.uk/ > > http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users > > _______________________________________________ > Nuke-users mailing list > [email protected], http://forums.thefoundry.co.uk/ > http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users >
# Nuke frame range fixer # Select read nodes and run the script. It will find the starting and ending frame in the sequence (if exist), and set the frame range to it. # (It skips other type of nodes, so you may select other types too) # Works only if counter is before the extension, and preceded by a . (point) # Example: # .../AX1_020_001-cg_fx_v008_cow_beauty.0108.iff # Useful for example if a 3d rendered sequence is loaded in nuke before the render has ended. # Comments are welcome # by Gabor L. Toth ([email protected]) # version 1.13 2016-10-19 - Working with deep read nodes # version 1.12 2016-02-05 - Silent mode # version 1.11 2014-01-10 - Changing max frame digits from 6 to 10 # version 1.10 2013-05-23 - Handling sequences with expressions in them # version 1.07 2011-06-07 - Inserting %0xd if not found, but there is a counter-like string ('.' followed by 1-6 digits then '.' again) # version 1.06 2010-08-23 - can be fed with a separate nodename, for cmdline # version 1.05 2009-11-10 - fixed sorting for linux # version 1.00 2009-10-21 - cleaned up version # version 0.12 2009-10-16 - skipping not existing directories # version 0.11 2009-09-10 - works properly with multiple sequences in the same folder. Handles pattern other than %04d too. # version 0.10 2009-09-09 - initial version import nuke import os import os.path import math import glob import re def glt_reloadRange(node = '', silent = 0): sn = [] if node =='': sn = [n for n in nuke.selectedNodes() if n.Class() == "Read" or n.Class() == "DeepRead"] else: sn.append(nuke.toNode(node)) print '\n<Glt_reloadRange> is running, silent = %s' % silent if sn != []: for n in sn: seqPathEval = n.knob('file').getEvaluatedValue() seqPathOriginal = n.knob('file').value() # could contain expressions if seqPathEval is not None: frame = re.search('\.[0-9]{1,10}\.', seqPathEval).group() if not silent: print 'Framenumber : %s' % frame pad = len(re.search('\.[0-9]{1,10}\.', seqPathEval).group())-2 seqPathEvalWithPCounter = re.sub('\.[0-9]{1,10}\.', ('.%0' + str(pad) + 'd.' ), seqPathEval) if re.match('.*\.%0[0-9]d.*', seqPathOriginal) == None: if re.search('.+\.[0-9]+\..+', seqPathOriginal): seqPathOriginal = re.sub('\.[0-9]{1,10}\.', ('.%0' + str(pad) + 'd.' ), seqPathOriginal ) n.knob('file').setValue(seqPathOriginal) print 'Changed readnode path, inserted %0xd counter!' else: print 'No counter!' return indx = seqPathEvalWithPCounter.find('%0') # getting padding format pattern = '%0' + seqPathEvalWithPCounter[indx + 2] + 'd' seqPathMask = seqPathEvalWithPCounter.replace(pattern, '*') # replacing %04d 'AUH_010_001-cg_li_v002_H1BodyRL.beauty.*.iff' if not silent: print '\nPathMask: %s' % (seqPathMask) seqDir = os.path.dirname(seqPathEvalWithPCounter) if not silent: print 'Directory: %s' % (seqDir) if os.path.exists(seqDir): files = os.listdir(seqDir) #print files #sorting files filteredFiles = glob.glob(seqPathMask) filteredFiles.sort() if len(filteredFiles) != 0: (firstFileName, ext) = os.path.splitext(filteredFiles[0]) firstFileTags = firstFileName.split('.') sfs = firstFileTags[-1] if not silent: print 'Extension: ' + ext sf = int (sfs) # converted to int if not silent: print "Start frame: %s" % (sf) (lastFileName, ext) = os.path.splitext(filteredFiles[len(filteredFiles)-1]) lastFileTags = lastFileName.split('.') efs = lastFileTags[-1] ef = int (efs) if not silent: print "End frame: %s" % (ef) n.knob('first').setValue(sf) n.knob('last').setValue(ef) else: if not silent: print 'No matching files in this directory! Skipping...' else: if not silent: print 'Warning! Directory doesnt exist: ' + seqDir else: pass else: print 'No selection'
_______________________________________________ Nuke-users mailing list [email protected], http://forums.thefoundry.co.uk/ http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
