From f89b4429fdc746499568084faf5321543e4ba981 Mon Sep 17 00:00:00 2001 From: pullusb Date: Wed, 4 Oct 2023 18:03:34 +0200 Subject: [PATCH] Update bg version looking for _3digits instead of righmost --- __init__.py | 2 +- operators/manage_planes.py | 33 ++++++++++++++++++++++----------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/__init__.py b/__init__.py index d0d3a60..a38388e 100644 --- a/__init__.py +++ b/__init__.py @@ -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": "", diff --git a/operators/manage_planes.py b/operators/manage_planes.py index eeeec0b..ccac4bc 100644 --- a/operators/manage_planes.py +++ b/operators/manage_planes.py @@ -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=(