68 lines
2.4 KiB
Python
68 lines
2.4 KiB
Python
info = {
|
|
'icon' : 'DECORATE_LIBRARY_OVERRIDE',
|
|
'description' : 'Check available library update',
|
|
'update' : False,
|
|
'fullreport': False,
|
|
}
|
|
|
|
import bpy
|
|
import os
|
|
from os import listdir, scandir
|
|
from os.path import abspath, relpath, join, dirname, basename, exists, isfile, isdir, splitext
|
|
import re, fnmatch, glob
|
|
from mathutils import Vector, Matrix
|
|
from math import radians, degrees
|
|
C = bpy.context
|
|
D = bpy.data
|
|
scene = C.scene
|
|
|
|
auto_update = info['update']#False
|
|
fullreport = info['fullreport']
|
|
|
|
## 1: all execpt num, 2: num, 3:ext
|
|
rseq = re.compile('^(.*?)(\d+)(\D*)$')
|
|
|
|
|
|
print('\n--library check--')
|
|
for ob in bpy.context.scene.objects:
|
|
if not ob.type == 'EMPTY': continue
|
|
if not ob.instance_collection: continue
|
|
if not ob.instance_collection.library: continue
|
|
lib = ob.instance_collection.library
|
|
if not lib: continue
|
|
fp = lib.filepath
|
|
if not fp: continue
|
|
rel_dir = dirname(fp)
|
|
abs_lib = abspath(bpy.path.abspath(fp))
|
|
if not exists(abs_lib):
|
|
print(f'Lib not found: obj: {ob.name} > instance: {ob.instance_collection.name}\n-> {abs_lib}')
|
|
continue
|
|
lib_dir = dirname(abs_lib)
|
|
lib_name = basename(abs_lib)
|
|
|
|
#same length ? #last modified ? #last by name without #must be 90% identical ? # parts without rightmost number must be identical (good enough)
|
|
regname = rseq.search(lib_name)
|
|
if not regname:
|
|
print(f'X - {lib_name} : could not identify version using regex: {rseq.pattern}')
|
|
continue
|
|
name_base = regname.group(1)
|
|
|
|
# filelist = [f for f in scandir(lib_dir) if f.is_file() and len(f.name) == len(lib_name)]
|
|
|
|
# more strict with filename
|
|
filelist = [f for f in scandir(lib_dir) if f.is_file() and len(f.name) == len(lib_name) and rseq.search(f.name) and rseq.search(f.name).group(1) == name_base]
|
|
filelist.sort(key=lambda x : x.name)#sort in place alphabetically
|
|
|
|
last = filelist[-1]
|
|
if last.name != lib.name:
|
|
print(f'/!\ Lib update found : obj: {ob.name} > instance: {ob.instance_collection.name}\n {lib_name} >> {last.name}\n')
|
|
|
|
if auto_update:
|
|
### use relocate or do it automagically...
|
|
nfp = join(dirname(fp), last.name)
|
|
lib.filepath = nfp
|
|
continue
|
|
|
|
if fullreport: print(f'Lib OK : obj: {ob.name} > instance: {ob.instance_collection.name} > file: {lib_name}')
|
|
## make breakdown popup for addon version
|
|
|