diff --git a/README.md b/README.md index 477ef95..5788ef0 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,10 @@ Panel in sidebar : 3D view > sidebar 'N' > Gpencil ## Changelog: +1.0.2: + +- pref: Added option to disable always remap relative on save in addon-preference + 1.0.1: - fix: copy paste problems diff --git a/__init__.py b/__init__.py index 8b46525..7a1a1af 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, 1), +"version": (1, 0, 2), "blender": (2, 91, 0), "location": "sidebar (N menu) > Gpencil > Toolbox / Gpencil properties", "warning": "", @@ -71,12 +71,30 @@ from pathlib import Path # self.palette_path = Path(bpy.path.abspath(self["palette_path"])).as_posix() +@persistent +def remap_relative(dummy): + all_path = [lib for lib in bpy.utils.blend_paths(local=True)] + bpy.ops.file.make_paths_relative() + for i, lib in enumerate(bpy.utils.blend_paths(local=True)): + if all_path[i] != lib: + print('Remapped:', all_path[i], '\n>> ', lib) + +def remap_on_save_update(self, context): + pref = get_addon_prefs() + if pref.use_relative_remap_on_save: + if not 'remap_relative' in [hand.__name__ for hand in bpy.app.handlers.save_pre]: + bpy.app.handlers.save_pre.append(remap_relative) + + else: + if 'remap_relative' in [hand.__name__ for hand in bpy.app.handlers.save_pre]: + bpy.app.handlers.save_pre.remove(remap_relative) + class GPTB_prefs(bpy.types.AddonPreferences): bl_idname = __name__ ## tabs - pref_tabs : bpy.props.EnumProperty( + pref_tabs : EnumProperty( items=(('PREF', "Preferences", "Change some preferences of the modal"), ('MAN_OPS', "Operator", "Operator to add Manually"), # ('TUTO', "Tutorial", "How to use the tool"), @@ -128,6 +146,13 @@ class GPTB_prefs(bpy.types.AddonPreferences): ## fps + use_relative_remap_on_save : BoolProperty( + name="Relative Remap On Save", + description="Always remap all external path to relative when saving\nNeed blender restart if changed", + default=True, + update=remap_on_save_update + ) + fps : IntProperty( name='Frame Rate', description="Fps of the project, Used to conform the file when you use Check file operator", @@ -275,17 +300,16 @@ class GPTB_prefs(bpy.types.AddonPreferences): # box.label(text='Render option:') box.prop(self, 'fps') row = box.row(align = True) - row.label(text='Render resolution') - row.prop(self, 'render_res_x', text='X') - row.prop(self, 'render_res_y', text='Y') + row.label(text='Render Resolution') + row.prop(self, 'render_res_x', text='Width') + row.prop(self, 'render_res_y', text='Height') ## Palette box.label(text='Palette library folder:') box.prop(self, 'palette_path') ## render output - - ## ?? maybe add an option for absolute path (not really usefull in prod) ?? box.prop(self, 'output_path') + box.prop(self, 'use_relative_remap_on_save') ### TODO add render settings @@ -383,16 +407,6 @@ class GPTB_prefs(bpy.types.AddonPreferences): # autotint_offset = bpy.props.IntProperty(name="Tint hue offset", description="offset the tint by this value for better color", default=0, min=-5000, max=5000, soft_min=-999, soft_max=999, step=1)#, subtype='PERCENTAGE' - - -@persistent -def remap_relative(dummy): - all_path = [lib for lib in bpy.utils.blend_paths(local=True)] - bpy.ops.file.make_paths_relative() - for i, lib in enumerate(bpy.utils.blend_paths(local=True)): - if all_path[i] != lib: - print('Remapped:', all_path[i], '\n>> ', lib) - classes = ( GPTB_prefs, GP_PG_ToolsSettings, @@ -422,10 +436,17 @@ def register(): keymaps.register() bpy.types.Scene.gptoolprops = bpy.props.PointerProperty(type = GP_PG_ToolsSettings) - bpy.app.handlers.save_pre.append(remap_relative) + # add handler (if option is on) + + if get_addon_prefs().use_relative_remap_on_save: + if not 'remap_relative' in [hand.__name__ for hand in bpy.app.handlers.save_pre]: + bpy.app.handlers.save_pre.append(remap_relative) + def unregister(): - bpy.app.handlers.save_pre.remove(remap_relative) + # remove handler + if 'remap_relative' in [hand.__name__ for hand in bpy.app.handlers.save_pre]: + bpy.app.handlers.save_pre.remove(remap_relative) keymaps.unregister() addon_updater_ops.unregister()