Fix redundant checker and add operator "Remove Redundant GP Stroke" (search)

This commit is contained in:
pullusb 2025-06-17 17:17:29 +02:00
parent 939b4f534f
commit a5dae7ee19
2 changed files with 33 additions and 4 deletions

View File

@ -3,6 +3,7 @@
4.1.3
- fixed: error in "remove stroke duplication" using file checker
- added: `Remove Redundant GP Stroke` Operator (Not exposed, avaialbe in search with developer extras enabled). Allow to use directly without going using file checker
4.1.2

View File

@ -10,17 +10,19 @@ from bpy.props import (BoolProperty,
CollectionProperty,
StringProperty)
def remove_stroke_exact_duplications(apply=True):
def remove_stroke_exact_duplications(apply=True, verbose=True):
'''Remove accidental stroke duplication (points exactly in the same place)
:apply: Remove the duplication instead of just listing dupes
return number of duplication found/deleted
'''
# TODO: Add additional check of material (even if unlikely to happen, better to avoid false positive)
ct = 0
if verbose:
print('\nRemove redundant strokdes in GP frames:')
gp_datas = [gp for gp in bpy.data.grease_pencils_v3]
for gp in gp_datas:
for l in gp.layers:
for f in l.frames:
for f_id, f in enumerate(l.frames):
stroke_list = []
idx_to_delete = []
@ -32,10 +34,35 @@ def remove_stroke_exact_duplications(apply=True):
else:
stroke_list.append(point_list)
if apply:
# Remove redundancy
if apply and idx_to_delete:
# Remove redundancy (carefull, passing an empty list delete all strokes)
print(f"{gp.name} > {l.name} > {f_id}: {len(idx_to_delete)} strokes")
f.drawing.remove_strokes(indices=idx_to_delete)
return ct
class GPTB_OT_remove_stroke_duplication(bpy.types.Operator):
bl_idname = "gp.remove_stroke_duplication"
bl_label = "Remove Redundant GP Stroke"
bl_description = "Within every frame, remove every strokes that are exactly superposed with a previous one"
bl_options = {"REGISTER", "UNDO"}
apply : bpy.props.BoolProperty(name="Apply Fixes", default=True,
description="Remove the duplication",
options={'SKIP_SAVE'})
def execute(self, context):
ct = remove_stroke_exact_duplications(apply=self.apply)
if ct > 0:
if self.apply:
self.report({'INFO'}, f'Removed {ct} strokes duplications')
else:
self.report({'INFO'}, f'Found {ct} strokes duplications')
else:
self.report({'INFO'}, 'No stroke duplication found')
return {'FINISHED'}
class GPTB_OT_file_checker(bpy.types.Operator):
bl_idname = "gp.file_checker"
bl_label = "Check File"
@ -798,6 +825,7 @@ GPTB_OT_copy_string_to_clipboard,
GPTB_OT_copy_multipath_clipboard,
GPTB_OT_file_checker,
GPTB_OT_links_checker,
GPTB_OT_remove_stroke_duplication,
)
def register():