Skip to content

Commit

Permalink
Fix T41022: [Node Wrangler] Image sequence import
Browse files Browse the repository at this point in the history
Failed when importing an image sequence where the start frame was something other than 1.
  • Loading branch information
gregzaal committed Aug 25, 2014
1 parent 09dd79e commit a6f74e9
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions node_efficiency_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
bl_info = {
"name": "Node Wrangler (aka Nodes Efficiency Tools)",
"author": "Bartek Skorupa, Greg Zaal",
"version": (3, 11),
"version": (3, 12),
"blender": (2, 71, 0),
"location": "Node Editor Properties Panel or Ctrl-Space",
"description": "Various tools to enhance and speed up node-based workflow",
Expand All @@ -36,6 +36,7 @@
from mathutils import Vector
from math import cos, sin, pi, hypot
from os import listdir
from glob import glob

#################
# rl_outputs:
Expand Down Expand Up @@ -2774,39 +2775,31 @@ def execute(self, context):
self.report({'ERROR'}, "Unsupported Node Tree type!")
return {'CANCELLED'}

# if last digit isn't a number, it's not a sequence
without_ext = '.'.join(filename.split('.')[:-1])

# if last digit isn't a number, it's not a sequence
if without_ext[-1].isdigit():
without_ext = without_ext[:-1] + '1'
else:
self.report({'ERROR'}, filename+" does not seem to be part of a sequence")
return {'CANCELLED'}


extension = filename.split('.')[-1]
reverse = without_ext[::-1] # reverse string
newreverse = ""
non_numbers = ""

count_numbers = 0
stop = False
for char in reverse:
if char.isdigit() and stop==False:
if char.isdigit():
count_numbers += 1
newreverse += '0' # replace numbers of image sequence with zeros
else:
stop = True
newreverse += char
non_numbers = char + non_numbers
break

newreverse = '1' + newreverse[1:]
without_ext = newreverse[::-1] # reverse string
without_num = without_ext[:count_numbers*-1]

# print (without_ext+'.'+filename.split('.')[-1])
# print (non_numbers)
extension = filename.split('.')[-1]
files = sorted(glob(directory + without_num + "[0-9]"*count_numbers + "." + extension))

num_frames = len(list(f for f in listdir(directory) if f.startswith(non_numbers)))

for x in range(count_numbers):
non_numbers += '#'
num_frames = len(files)

nodes_list = [node for node in nodes]
if nodes_list:
Expand All @@ -2821,14 +2814,18 @@ def execute(self, context):
xloc = 0
yloc = 0

name_with_hashes = without_num + "#"*count_numbers + '.' + extension

node = nodes.new(node_type)
node.location.x = xloc
node.location.y = yloc + 110
node.label = non_numbers+'.'+extension
node.label = name_with_hashes

img = bpy.data.images.load(directory+(without_ext+'.'+extension))
img.source = 'SEQUENCE'
img.name = name_with_hashes
node.image = img
node.frame_offset = int(files[0][len(without_num)+len(directory):-1*(len(extension)+1)]) - 1 # separate the number from the file name of the first file
if context.space_data.node_tree.type == 'SHADER':
node.image_user.frame_duration = num_frames
else:
Expand Down

0 comments on commit a6f74e9

Please sign in to comment.