From 651f9e7747f5d73f73f35d74af9978994643e915 Mon Sep 17 00:00:00 2001 From: Pullusb Date: Tue, 25 Jan 2022 15:13:08 +0100 Subject: [PATCH] Layer name manager fix modifier targets 1.9.4 - feat: renaming using the name_manager take care of changing layer target values in GP modifiers --- CHANGELOG.md | 4 ++++ OP_layer_manager.py | 19 +++++++++++++++++-- __init__.py | 2 +- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 609bb16..9388bdd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +1.9.4 + +- feat: renaming using the name_manager take care of changing layer target values in GP modifiers + 1.9.3 - feat: Add an update button at bottom of preferences if addon is a cloned repository diff --git a/OP_layer_manager.py b/OP_layer_manager.py index f22ee37..cd96dca 100644 --- a/OP_layer_manager.py +++ b/OP_layer_manager.py @@ -23,12 +23,14 @@ PATTERN = r'^(?P-\s)?(?P[A-Z]{2}_)?(?P.*?)(?P_[A-Z]{2})?(? def layer_name_build(layer, prefix='', desc='', suffix=''): - '''GET a layer and argumen to build and assign name''' + '''GET a layer and argument to build and assign name + return new name + ''' prefs = get_addon_prefs() sep = prefs.separator - name = layer.info + name = old = layer.info pattern = PATTERN.replace('_', sep) # set separator @@ -68,6 +70,19 @@ def layer_name_build(layer, prefix='', desc='', suffix=''): new = f'{grp}{tag}{name}{sfix}' layer.info = new + + ## update name in modifier targets + if old != new: + # find objects using this GP datablock + for ob_user in [o for o in bpy.data.objects if o.data == layer.id_data]: # bpy.context.scene.objects + # maybe a more elegant way exists to find all objects users ? + + # update Gpencil modifier targets + for mod in ob_user.grease_pencil_modifiers: + if not hasattr(mod, 'layer'): + continue + if mod.layer == old: + mod.layer = new """ def layer_name_build(layer, prefix='', prefix2='', desc='', suffix=''): diff --git a/__init__.py b/__init__.py index de96b3d..d98c894 100755 --- a/__init__.py +++ b/__init__.py @@ -15,7 +15,7 @@ bl_info = { "name": "GP toolbox", "description": "Tool set for Grease Pencil in animation production", "author": "Samuel Bernou, Christophe Seux", -"version": (1, 9, 3), +"version": (1, 9, 4), "blender": (2, 91, 0), "location": "Sidebar (N menu) > Gpencil > Toolbox / Gpencil properties", "warning": "",