Skip to content

Instantly share code, notes, and snippets.

@whoiscarlo
Created December 23, 2022 03:06
Show Gist options
  • Save whoiscarlo/8f7d7d02e046725c2513113dd5cd9847 to your computer and use it in GitHub Desktop.
Save whoiscarlo/8f7d7d02e046725c2513113dd5cd9847 to your computer and use it in GitHub Desktop.
Nuke - Create a read node from an image sequence
import os
import nuke
def get_padding(seqNumbers):
'''
Get correct number of padding for image sequence
'''
size = len(seqNumbers)
padding = ''
for ii in range(size):
padding += '#'
return padding
def create_image_sequence_path_with_padding(imageSequenceFolder):
'''
Create a nuke image sequence path with proper padding count
'''
files = os.listdir(imageSequenceFolder)
## Result: ['shot001_plate_v001.1001.jpeg', 'shot001_plate_v001.1002.jpeg', ....]
if len(files) != 0:
seqNumbers = files[0].split('.')[-2]
## Result: 1001
padding = self.get_padding(seqNumbers)
## Result: ####
fileSeq = files[0].replace(seqNumbers, padding)
## Result: shot001_plate_v001.####.jpeg
imageSequencePath = os.path.join(imageSequenceFolder, fileSeq)
## Result: /this/random/path/seq001/shot001/comp/shot001_plate_v001.####.jpeg
return imageSequencePath
def createImageSequenceReadNode(imageSequencePath):
imageSequenceFolder = os.path.split(imageSequencePath)[0]
## Result: /this/random/path/seq001/shot001/comp/
files = sorted(os.listdir(imageSequenceFolder))
## Result: ['shot001_plate_v001.1001.jpeg', 'shot001_plate_v001.1002.jpeg', ...., 'shot001_plate_v001.1250.jpeg']
firstFrame = int(files[0].split('.')[-2])
## Result: 1001
lastFrame = int(files[-1].split('.')[-2])
## Result: 1250
readNode = nuke.createNode('Read')
readNode['file'].setValue(imageSequencePath)
readNode['first'].setValue(firstFrame)
readNode['last'].setValue(lastFrame)
readNode['origfirst'].setValue(firstFrame)
readNode['origlast'].setValue(lastFrame)
def main():
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment