add toggle remap relative on save

1.0.2:

- pref: Added option to disable always remap relative on save in addon-preference
gpv2
Pullusb 2021-03-07 00:39:32 +01:00
parent c9266b7efe
commit d7da95ac5d
2 changed files with 44 additions and 19 deletions

View File

@ -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

View File

@ -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()