Update bg version looking for _3digits instead of righmost

master
pullusb 2023-10-04 18:03:34 +02:00
parent 7cfcae25e5
commit f89b4429fd
2 changed files with 23 additions and 12 deletions

View File

@ -4,7 +4,7 @@ bl_info = {
"name": "Background plane manager",
"description": "Manage the background image planes and grease pencil object relative to a camera",
"author": "Samuel Bernou",
"version": (0, 5, 0),
"version": (0, 5, 1),
"blender": (3, 5, 0),
"location": "View3D",
"warning": "",

View File

@ -315,7 +315,11 @@ class BPM_OT_update_bg_images(Operator):
print('Updating barckground images:')
ct = 0
right_num = re.compile(r'(\d+)(?!.*\d)')
pb = 0
# TODO: remove '?' after v on clean project
re_version = re.compile(r'_v?\d{3}') # _001 # Underscored 3 digit
for item in context.scene.bg_props.planes:
if item.type != 'bg':
continue
@ -328,20 +332,24 @@ class BPM_OT_update_bg_images(Operator):
img = Path(bpy.path.abspath(image.filepath))
if not re.search(r'\d+$', img.stem):
print(f'SKIP: object "{bg_obj.name}" > image "{image.name}" does not end with version')
if not re_version.search(img.stem):
print(f'SKIP: object "{bg_obj.name}" > image "{image.name}" does not have version in name')
continue
img_folder = img.parent
# List in folder : only file versionned, with same suffix and same basename
# List in folder : only file versionned, with same suffix and same basename (and suffix after version)
images_list = [i for i in img_folder.iterdir() if i.is_file()\
and re.search(r'\d+$', i.stem)\
and re_version.search(i.stem)\
and i.suffix == img.suffix\
and right_num.sub('', img.stem) == right_num.sub('', i.stem)]
## images_list should neveer be empty (source img should be listed)
# for i in images_list:
# print(i.stem)
and re_version.sub('', img.stem) == re_version.sub('', i.stem)]
if not images_list:
## images_list should never be empty (at least source img should be listed)
print(f'PROBLEM: Empty list with image {image.name} -> not found at: {image.filepath}')
pb += 1
continue
images_list.sort()
last = images_list[-1]
if last == img:
@ -383,6 +391,9 @@ class BPM_OT_update_bg_images(Operator):
else:
self.report({'INFO'}, 'All background images are up to date')
if pb:
self.report({'WARNING'}, f'{pb} images filepaths are not valid!')
return {"FINISHED"}
classes=(