From d1b03c804c7398cb9132ff3aa3f8cbe2e0fc2c1f Mon Sep 17 00:00:00 2001 From: pullusb Date: Tue, 7 Feb 2023 12:55:48 +0100 Subject: [PATCH] file checker remove stroke duplicates 2.2.0 - added: _Remove redundant stroke_ in File checker (Just list duplicate numbers in "check only" mode) --- CHANGELOG.md | 6 +++++- OP_file_checker.py | 33 +++++++++++++++++++++++++++++++++ __init__.py | 3 ++- properties.py | 5 +++++ 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7481855..aed12af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,13 @@ # Changelog +2.2.0 + +- added: _Remove redundant stroke_ in File checker (Just list duplicate numbers in "check only" mode) + 2.1.6 -- Fixed: Prevent some keymaps to register when blender is launched in background mode +- fixed: Prevent some keymaps to register when blender is launched in background mode 2.1.5 diff --git a/OP_file_checker.py b/OP_file_checker.py index 37e885b..f652265 100755 --- a/OP_file_checker.py +++ b/OP_file_checker.py @@ -1,8 +1,33 @@ import bpy import os from pathlib import Path +import numpy as np from . import utils +def remove_stroke_exact_duplications(apply=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) + ct = 0 + gp_datas = [gp for gp in bpy.data.grease_pencils] + for gp in gp_datas: + for l in gp.layers: + for f in l.frames: + stroke_list = [] + for s in reversed(f.strokes): + + point_list = [p.co for p in s.points] + + if point_list in stroke_list: + ct += 1 + if apply: + # Remove redundancy + f.strokes.remove(s) + else: + stroke_list.append(point_list) + return ct class GPTB_OT_file_checker(bpy.types.Operator): bl_idname = "gp.file_checker" bl_label = "Check File" @@ -26,6 +51,7 @@ class GPTB_OT_file_checker(bpy.types.Operator): # Set filepath type # Set Lock object mode state # Disable use light on all object + # Remove redundant strokes in frames def invoke(self, context, event): # need some self-control (I had to...) @@ -234,6 +260,12 @@ class GPTB_OT_file_checker(bpy.types.Operator): if apply: bpy.context.scene.tool_settings.lock_object_mode = False + if fix.remove_redundant_strokes: + ct = remove_stroke_exact_duplications(apply=apply) + if ct > 0: + mess = f'Removed {ct} strokes duplications' if apply else f'Found {ct} strokes duplications' + problems.append(mess) + # ## Set onion skin filter to 'All type' # fix_kf_type = 0 # for gp in bpy.data.grease_pencils:#from data @@ -505,6 +537,7 @@ class GPTB_OT_list_object_visibility(bpy.types.Operator): return context.window_manager.invoke_props_dialog(self, width=250) def draw(self, context): + # TODO: Add visibility check with viewlayer visibility as well layout = self.layout for o in self.ob_list: row = layout.row() diff --git a/__init__.py b/__init__.py index 513a62f..9be94af 100755 --- a/__init__.py +++ b/__init__.py @@ -4,7 +4,7 @@ bl_info = { "name": "GP toolbox", "description": "Tool set for Grease Pencil in animation production", "author": "Samuel Bernou, Christophe Seux", -"version": (2, 1, 6), +"version": (2, 2, 0), "blender": (3, 0, 0), "location": "Sidebar (N menu) > Gpencil > Toolbox / Gpencil properties", "warning": "", @@ -643,6 +643,7 @@ class GPTB_prefs(bpy.types.AddonPreferences): col.prop(self.fixprops, 'list_gp_mod_vis_conflict') col.prop(self.fixprops, 'list_broken_mod_targets') col.prop(self.fixprops, 'autokey_add_n_replace') + col.prop(self.fixprops, 'remove_redundant_strokes') #-# col.prop(self.fixprops, 'set_cursor_type') # col = layout.column() diff --git a/properties.py b/properties.py index 9b6466f..10cb2f2 100755 --- a/properties.py +++ b/properties.py @@ -110,6 +110,11 @@ class GP_PG_FixSettings(PropertyGroup): name="Autokey Mode Add and Replace", description="Change autokey mode back to 'Add & Replace'", default=True, options={'HIDDEN'}) + + remove_redundant_strokes : BoolProperty( + name="Remove Redundant Strokes", + description="Remove GP strokes duplication. When points are exactly identical within the same frame", + default=True, options={'HIDDEN'}) # set_cursor_type : BoolProperty( # name="Set Select Cursor Mode",