Fix file checker's redundant strokes delete

4.1.3

- fixed: error in "remove stroke duplication" using file checker
This commit is contained in:
pullusb 2025-06-17 16:57:20 +02:00
parent 3624f5cabd
commit 939b4f534f
5 changed files with 24 additions and 16 deletions

View File

@ -1,5 +1,8 @@
# Changelog # Changelog
4.1.3
- fixed: error in "remove stroke duplication" using file checker
4.1.2 4.1.2

View File

@ -15,24 +15,26 @@ def remove_stroke_exact_duplications(apply=True):
:apply: Remove the duplication instead of just listing dupes :apply: Remove the duplication instead of just listing dupes
return number of duplication found/deleted return number of duplication found/deleted
''' '''
# TODO: add additional check of material (even if unlikely to happen) # TODO: Add additional check of material (even if unlikely to happen, better to avoid false positive)
ct = 0 ct = 0
gp_datas = [gp for gp in bpy.data.grease_pencils] gp_datas = [gp for gp in bpy.data.grease_pencils_v3]
for gp in gp_datas: for gp in gp_datas:
for l in gp.layers: for l in gp.layers:
for f in l.frames: for f in l.frames:
stroke_list = [] stroke_list = []
for s in reversed(f.drawing.strokes): idx_to_delete = []
point_list = [p.position for p in s.points] for idx, s in enumerate(f.drawing.strokes):
point_list = [p.position.copy() for p in s.points]
if point_list in stroke_list: if point_list in stroke_list:
ct += 1 ct += 1
if apply: idx_to_delete.append(idx)
# Remove redundancy
f.drawing.strokes.remove(s)
else: else:
stroke_list.append(point_list) stroke_list.append(point_list)
if apply:
# Remove redundancy
f.drawing.remove_strokes(indices=idx_to_delete)
return ct return ct
class GPTB_OT_file_checker(bpy.types.Operator): class GPTB_OT_file_checker(bpy.types.Operator):
bl_idname = "gp.file_checker" bl_idname = "gp.file_checker"
@ -267,6 +269,7 @@ class GPTB_OT_file_checker(bpy.types.Operator):
bpy.context.scene.tool_settings.lock_object_mode = False bpy.context.scene.tool_settings.lock_object_mode = False
if fix.remove_redundant_strokes: if fix.remove_redundant_strokes:
print('removing redundant strokes')
ct = remove_stroke_exact_duplications(apply=apply) ct = remove_stroke_exact_duplications(apply=apply)
if ct > 0: if ct > 0:
mess = f'Removed {ct} strokes duplications' if apply else f'Found {ct} strokes duplications' mess = f'Removed {ct} strokes duplications' if apply else f'Found {ct} strokes duplications'
@ -274,7 +277,7 @@ class GPTB_OT_file_checker(bpy.types.Operator):
# ## Set onion skin filter to 'All type' # ## Set onion skin filter to 'All type'
# fix_kf_type = 0 # fix_kf_type = 0
# for gp in bpy.data.grease_pencils:#from data # for gp in bpy.data.grease_pencils_v3:#from data
# if not gp.is_annotation: # if not gp.is_annotation:
# if gp.onion_keyframe_type != 'ALL': # if gp.onion_keyframe_type != 'ALL':
# gp.onion_keyframe_type = 'ALL' # gp.onion_keyframe_type = 'ALL'

View File

@ -166,7 +166,7 @@ class GPTB_OT_import_obj_palette(Operator):
# unlink objects and their gp data # unlink objects and their gp data
for src_ob in linked_objs: for src_ob in linked_objs:
bpy.data.grease_pencils.remove(src_ob.data) bpy.data.grease_pencils_v3.remove(src_ob.data)
return {"FINISHED"} return {"FINISHED"}

View File

@ -4,7 +4,7 @@ bl_info = {
"name": "GP toolbox", "name": "GP toolbox",
"description": "Tool set for Grease Pencil in animation production", "description": "Tool set for Grease Pencil in animation production",
"author": "Samuel Bernou, Christophe Seux", "author": "Samuel Bernou, Christophe Seux",
"version": (4, 1, 2), "version": (4, 1, 3),
"blender": (4, 3, 0), "blender": (4, 3, 0),
"location": "Sidebar (N menu) > Gpencil > Toolbox / Gpencil properties", "location": "Sidebar (N menu) > Gpencil > Toolbox / Gpencil properties",
"warning": "", "warning": "",

View File

@ -11,10 +11,12 @@ from bpy.props import (
from .OP_cursor_snap_canvas import cursor_follow_update from .OP_cursor_snap_canvas import cursor_follow_update
from .OP_layer_manager import layer_name_build from .OP_layer_manager import layer_name_build
def change_edit_lines_opacity(self, context):
for gp in bpy.data.grease_pencils: ## Obsolete: Gpv3 has no edit line color anymore
if not gp.is_annotation: # def change_edit_lines_opacity(self, context):
gp.edit_line_color[3]=self.edit_lines_opacity # for gp in bpy.data.grease_pencils:
# if not gp.is_annotation:
# gp.edit_line_color[3]=self.edit_lines_opacity
def update_layer_name(self, context): def update_layer_name(self, context):