Add disable use light in file checker

1.9.1

- fix: add error handling on palette linker when blend_path isn't valid anymore
- added: file checker entry, Disable all GP object `use lights` (True by default in addon pref `checklist`)
- added: WIP of Batch reproject all on cursor.
  - No UI. In search menu `Flat Reproject Selected On cursor` (idname `gp.batch_flat_reproject`)
This commit is contained in:
Pullusb
2022-01-18 22:53:08 +01:00
parent 4ac743cd32
commit 7985844226
8 changed files with 363 additions and 18 deletions
+109
View File
@@ -79,6 +79,10 @@ class GPTB_OT_import_obj_palette(Operator):
self.report({'ERROR'}, 'Not supported yet, use link')
return {'CANCELLED'}
if not Path(blend_path).exists():
utils.show_message_box([['gp.palettes_reload_blends', 'Invalid blend path! Click here to refresh source blends', 'FILE_REFRESH']], 'Invalid Palette', 'ERROR')
return {'CANCELLED'}
# get relative path
blend_path = bpy.path.relpath(blend_path)
@@ -197,6 +201,109 @@ class GPTB_OT_palette_fuzzy_search_obj(Operator):
self.report({'INFO'}, f'Select {bl_props.objects[bl_props.ob_idx].name} (match at {final_ratio*100:.1f}% with "{context.object.name}")')
return {"FINISHED"}
## Unused for now, all libs are linked to one library data. need to replace material links one by one.
class GPTB_OT_palette_version_update(Operator):
bl_idname = "gptb.palette_version_update"
bl_label = "Update Palette Version"
bl_description = "Update linked material to selected palette version if curent link has same basename"
bl_options = {"REGISTER"}
mat_scope : EnumProperty(
name='Targeted Materials',
items=(('ALL', "All Materials", "Update all linked material in file to next version"),
('SELECTED', "Selected Objects", "Update all linked material on selected gp objects"),
),
default='ALL',
description='Choose material targeted for library update'
)
mat_type : EnumProperty(
name='Materials Type',
items=(('ALL', "All Materials", "Update both gp and obj materials"),
('GP', "Gpencil Materials", "update only grease pencil materials"),
('OBJ', "Non-Gpencil Materials", "update only non-gpencil objects materials"),
),
default='GP',
description='Filter material type for library update'
)
def invoke(self, context, event):
self.bl_props = context.scene.bl_palettes_props
if not self.bl_props.blends or not self.bl_props.blends[0].blend_path:
self.report({'ERROR'}, 'No blend selected')
return {"CANCELLED"}
return context.window_manager.invoke_props_dialog(self, width=450)
def draw(self, context):
layout = self.layout
layout.label(text=f'Update links path to palette: {self.bl_props.blends[self.bl_props.bl_idx].blend_name}', icon='LINK_BLEND')
self.bl_props
layout.prop(self, 'mat_scope')
layout.prop(self, 'mat_type')
col = layout.column(align=True)
col.label(text='Does not check if material exists in target blend', icon='INFO')
col.label(text='Just change source filepath if different version of same source name is found')
# col.label(text='version of same source name is found')
def execute(self, context):
if self.mat_scope == 'SELECTED' and not context.selected_objects:
self.report({'ERROR'}, 'No selected objects')
return {"CANCELLED"}
bl_props = context.scene.bl_palettes_props
bl = bl_props.blends[bl_props.bl_idx]
bl_name, bl_path = bl.blend_name, bl.blend_path
if not Path(bl_path).exists():
self.report({'ERROR'}, f'Current selected blend source seem unreachable, try to refresh\ninvalid path: {bl_path}')
return {"CANCELLED"}
reversion = re.compile(r'\d{2,4}$') # version padding from 2 to 4
bl_relpath = bpy.path.relpath(bl_path)
if self.mat_scope == 'SELECTED':
pool = []
for o in context.selected_objects:
for m in o.data.materials:
pool.append(m)
elif self.mat_scope == 'ALL':
pool = [m for m in bpy.data.materials]
ct = 0
for m in pool:
if not m.library:
continue
if self.mat_type == 'GP' and not m.is_grease_pencil:
continue
if self.mat_type == 'OBJ' and m.is_grease_pencil:
continue
cur_fp = m.library.filepath
if not cur_fp:
print(f'! {m.name} has an empty library filepath !')
continue
p_cur_fp = Path(cur_fp)
if p_cur_fp.stem == bl_name:
continue # already good
if reversion.sub('', p_cur_fp.stem) != reversion.sub('', bl_name):
continue # not same stem base
# Same stem without version, can update to this one
print(f'{m.name}: {p_cur_fp} >> {bl_relpath}')
ct += 1
m.library.filepath = bl_relpath
if ct:
self.report({'INFO'}, f'{ct} material link path updated')
else:
self.report({'WARNING'}, 'No material path updated')
return {"FINISHED"}
#--- UI LIST
class GPTB_UL_blend_list(UIList):
@@ -452,6 +559,8 @@ GPTB_UL_object_list,
GPTB_PG_palette_settings,
GPTB_OT_import_obj_palette,
# GPTB_OT_palette_version_update,
# TEST_OT_import_obj_palette_test,
)