From 43797ff5906584d777245de142382052ce4921c3 Mon Sep 17 00:00:00 2001 From: Pullusb Date: Tue, 16 Mar 2021 22:52:26 +0100 Subject: [PATCH] feat: transfer materials to objects 1.0.3: - feat: add "Append Materials To Selected" to material submenu. Append materials to other selected GP objects if there aren't there. --- OP_palettes.py | 40 ++++++++++++++++++++++++++++++++++++++++ README.md | 15 +++++++++++++++ UI_tools.py | 1 + __init__.py | 2 +- 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/OP_palettes.py b/OP_palettes.py index b33e7cc..9f56a3b 100644 --- a/OP_palettes.py +++ b/OP_palettes.py @@ -243,11 +243,51 @@ class GPTB_OT_load_blend_palette(bpy.types.Operator, ImportHelper): return {"FINISHED"} + +class GPTB_OT_copy_active_to_selected_palette(bpy.types.Operator): + bl_idname = "gp.copy_active_to_selected_palette" + bl_label = "Append Materials To Selected" + bl_description = "Copy all the materials of the active GP objects to the material stack of all the other selected GP" + bl_options = {"REGISTER"} # , "INTERNAL" + + # path_to_pal : bpy.props.StringProperty(name="paht to palette", description="path to the palette", default="") + @classmethod + def poll(cls, context): + return context.object and context.object.type == 'GPENCIL' + + def execute(self, context): + ob = context.object + if not len(ob.data.materials): + self.report({'ERROR'}, 'No materials to transfer') + return {"CANCELLED"} + + selection = [o for o in context.selected_objects if o.type == 'GPENCIL' and o != ob] + + if not selection: + self.report({'ERROR'}, 'Need to have other Grease pencil objects selected to receive active object materials') + return {"CANCELLED"} + + ct = 0 + for o in selection: + for mat in ob.data.materials: + if mat in o.data.materials[:]: + continue + o.data.materials.append(mat) + ct += 1 + + if ct: + self.report({'INFO'}, f'{ct} Materials appended') + else: + self.report({'WARNING'}, 'All materials are already in other selected object') + + return {"FINISHED"} + classes = ( GPTB_OT_load_palette, GPTB_OT_save_palette, GPTB_OT_load_default_palette, GPTB_OT_load_blend_palette, +GPTB_OT_copy_active_to_selected_palette, ) def register(): diff --git a/README.md b/README.md index 5788ef0..526a938 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,17 @@ Also Possible to copy whole selected layers. - Auto update : you have an updater in the addon preference tabs (use the [CGcookie addon updater](https://github.com/CGCookie/blender-addon-updater)) + +**Palette management** + +In material submenu you have mutliple new entry: + +- Copy Materials To Selected : copy all material to other selected GP (difference with Ctrl+L > materials is that it doesn't erase materials, only append those that are not in other's materials stack) + +- Load/Save Json palette : Save/load materials externally to a json file from/to the active material stack. + +- Load Color palette : same as the load above exept it loads directly from a blend file (all the material that the blend contains) + ### Where ? Panel in sidebar : 3D view > sidebar 'N' > Gpencil @@ -101,6 +112,10 @@ Panel in sidebar : 3D view > sidebar 'N' > Gpencil ## Changelog: +1.0.3: + +- feat: add "Append Materials To Selected" to material submenu. Append materials to other selected GP objects if there aren't there. + 1.0.2: - pref: Added option to disable always remap relative on save in addon-preference diff --git a/UI_tools.py b/UI_tools.py index ec586db..6413c8d 100644 --- a/UI_tools.py +++ b/UI_tools.py @@ -316,6 +316,7 @@ def palette_manager_menu(self, context): layout.separator() prefs = get_addon_prefs() + layout.operator("gp.copy_active_to_selected_palette", text='Append Materials To Selected', icon='MATERIAL') layout.operator("gp.load_palette", text='Load json Palette', icon='IMPORT').filepath = prefs.palette_path layout.operator("gp.save_palette", text='Save json Palette', icon='EXPORT').filepath = prefs.palette_path layout.operator("gp.load_blend_palette", text='Load color Palette', icon='COLOR').filepath = prefs.palette_path diff --git a/__init__.py b/__init__.py index 7a1a1af..bf71677 100644 --- a/__init__.py +++ b/__init__.py @@ -15,7 +15,7 @@ bl_info = { "name": "GP toolbox", "description": "Set of tools for Grease Pencil in animation production", "author": "Samuel Bernou", -"version": (1, 0, 2), +"version": (1, 0, 3), "blender": (2, 91, 0), "location": "sidebar (N menu) > Gpencil > Toolbox / Gpencil properties", "warning": "",