Update bg version looking for _3digits instead of righmost
This commit is contained in:
		
							parent
							
								
									7cfcae25e5
								
							
						
					
					
						commit
						f89b4429fd
					
				| @ -4,7 +4,7 @@ bl_info = { | |||||||
|     "name": "Background plane manager", |     "name": "Background plane manager", | ||||||
|     "description": "Manage the background image planes and grease pencil object relative to a camera", |     "description": "Manage the background image planes and grease pencil object relative to a camera", | ||||||
|     "author": "Samuel Bernou", |     "author": "Samuel Bernou", | ||||||
|     "version": (0, 5, 0), |     "version": (0, 5, 1), | ||||||
|     "blender": (3, 5, 0), |     "blender": (3, 5, 0), | ||||||
|     "location": "View3D", |     "location": "View3D", | ||||||
|     "warning": "", |     "warning": "", | ||||||
|  | |||||||
| @ -315,7 +315,11 @@ class BPM_OT_update_bg_images(Operator): | |||||||
|         print('Updating barckground images:') |         print('Updating barckground images:') | ||||||
| 
 | 
 | ||||||
|         ct = 0 |         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: |         for item in context.scene.bg_props.planes: | ||||||
|             if item.type != 'bg': |             if item.type != 'bg': | ||||||
|                 continue |                 continue | ||||||
| @ -328,19 +332,23 @@ class BPM_OT_update_bg_images(Operator): | |||||||
|                  |                  | ||||||
|                 img = Path(bpy.path.abspath(image.filepath)) |                 img = Path(bpy.path.abspath(image.filepath)) | ||||||
| 
 | 
 | ||||||
|                 if not re.search(r'\d+$', img.stem): |                 if not re_version.search(img.stem): | ||||||
|                     print(f'SKIP: object "{bg_obj.name}" > image "{image.name}" does not end with version') |                     print(f'SKIP: object "{bg_obj.name}" > image "{image.name}" does not have version in name') | ||||||
|  |                     continue | ||||||
|  | 
 | ||||||
|                 img_folder = img.parent |                 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()\ |                 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 i.suffix == img.suffix\ | ||||||
|                                 and right_num.sub('', img.stem) == right_num.sub('', i.stem)] |                                 and re_version.sub('', img.stem) == re_version.sub('', i.stem)] | ||||||
| 
 | 
 | ||||||
|                 ## images_list should neveer be empty (source img should be listed) |                 if not images_list: | ||||||
|                 # for i in images_list: |                     ## images_list should never be empty (at least source img should be listed) | ||||||
|                 #     print(i.stem) |                     print(f'PROBLEM: Empty list with image {image.name} -> not found at: {image.filepath}') | ||||||
|  |                     pb += 1 | ||||||
|  |                     continue | ||||||
| 
 | 
 | ||||||
|                 images_list.sort() |                 images_list.sort() | ||||||
|                 last = images_list[-1] |                 last = images_list[-1] | ||||||
| @ -383,6 +391,9 @@ class BPM_OT_update_bg_images(Operator): | |||||||
|         else: |         else: | ||||||
|             self.report({'INFO'}, 'All background images are up to date') |             self.report({'INFO'}, 'All background images are up to date') | ||||||
| 
 | 
 | ||||||
|  |         if pb: | ||||||
|  |             self.report({'WARNING'}, f'{pb} images filepaths are not valid!') | ||||||
|  | 
 | ||||||
|         return {"FINISHED"} |         return {"FINISHED"} | ||||||
| 
 | 
 | ||||||
| classes=( | classes=( | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user