add toggle remap relative on save
1.0.2: - pref: Added option to disable always remap relative on save in addon-preferencegpv2
parent
c9266b7efe
commit
d7da95ac5d
|
@ -101,6 +101,10 @@ Panel in sidebar : 3D view > sidebar 'N' > Gpencil
|
||||||
|
|
||||||
## Changelog:
|
## Changelog:
|
||||||
|
|
||||||
|
1.0.2:
|
||||||
|
|
||||||
|
- pref: Added option to disable always remap relative on save in addon-preference
|
||||||
|
|
||||||
1.0.1:
|
1.0.1:
|
||||||
|
|
||||||
- fix: copy paste problems
|
- fix: copy paste problems
|
||||||
|
|
55
__init__.py
55
__init__.py
|
@ -15,7 +15,7 @@ bl_info = {
|
||||||
"name": "GP toolbox",
|
"name": "GP toolbox",
|
||||||
"description": "Set of tools for Grease Pencil in animation production",
|
"description": "Set of tools for Grease Pencil in animation production",
|
||||||
"author": "Samuel Bernou",
|
"author": "Samuel Bernou",
|
||||||
"version": (1, 0, 1),
|
"version": (1, 0, 2),
|
||||||
"blender": (2, 91, 0),
|
"blender": (2, 91, 0),
|
||||||
"location": "sidebar (N menu) > Gpencil > Toolbox / Gpencil properties",
|
"location": "sidebar (N menu) > Gpencil > Toolbox / Gpencil properties",
|
||||||
"warning": "",
|
"warning": "",
|
||||||
|
@ -71,12 +71,30 @@ from pathlib import Path
|
||||||
# self.palette_path = Path(bpy.path.abspath(self["palette_path"])).as_posix()
|
# 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):
|
class GPTB_prefs(bpy.types.AddonPreferences):
|
||||||
bl_idname = __name__
|
bl_idname = __name__
|
||||||
|
|
||||||
## tabs
|
## tabs
|
||||||
|
|
||||||
pref_tabs : bpy.props.EnumProperty(
|
pref_tabs : EnumProperty(
|
||||||
items=(('PREF', "Preferences", "Change some preferences of the modal"),
|
items=(('PREF', "Preferences", "Change some preferences of the modal"),
|
||||||
('MAN_OPS', "Operator", "Operator to add Manually"),
|
('MAN_OPS', "Operator", "Operator to add Manually"),
|
||||||
# ('TUTO', "Tutorial", "How to use the tool"),
|
# ('TUTO', "Tutorial", "How to use the tool"),
|
||||||
|
@ -128,6 +146,13 @@ class GPTB_prefs(bpy.types.AddonPreferences):
|
||||||
|
|
||||||
## fps
|
## 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(
|
fps : IntProperty(
|
||||||
name='Frame Rate',
|
name='Frame Rate',
|
||||||
description="Fps of the project, Used to conform the file when you use Check file operator",
|
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.label(text='Render option:')
|
||||||
box.prop(self, 'fps')
|
box.prop(self, 'fps')
|
||||||
row = box.row(align = True)
|
row = box.row(align = True)
|
||||||
row.label(text='Render resolution')
|
row.label(text='Render Resolution')
|
||||||
row.prop(self, 'render_res_x', text='X')
|
row.prop(self, 'render_res_x', text='Width')
|
||||||
row.prop(self, 'render_res_y', text='Y')
|
row.prop(self, 'render_res_y', text='Height')
|
||||||
## Palette
|
## Palette
|
||||||
box.label(text='Palette library folder:')
|
box.label(text='Palette library folder:')
|
||||||
box.prop(self, 'palette_path')
|
box.prop(self, 'palette_path')
|
||||||
|
|
||||||
## render output
|
## render output
|
||||||
|
|
||||||
## ?? maybe add an option for absolute path (not really usefull in prod) ??
|
|
||||||
box.prop(self, 'output_path')
|
box.prop(self, 'output_path')
|
||||||
|
box.prop(self, 'use_relative_remap_on_save')
|
||||||
|
|
||||||
### TODO add render settings
|
### 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'
|
# 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 = (
|
classes = (
|
||||||
GPTB_prefs,
|
GPTB_prefs,
|
||||||
GP_PG_ToolsSettings,
|
GP_PG_ToolsSettings,
|
||||||
|
@ -422,9 +436,16 @@ def register():
|
||||||
keymaps.register()
|
keymaps.register()
|
||||||
bpy.types.Scene.gptoolprops = bpy.props.PointerProperty(type = GP_PG_ToolsSettings)
|
bpy.types.Scene.gptoolprops = bpy.props.PointerProperty(type = GP_PG_ToolsSettings)
|
||||||
|
|
||||||
|
# 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)
|
bpy.app.handlers.save_pre.append(remap_relative)
|
||||||
|
|
||||||
|
|
||||||
def unregister():
|
def unregister():
|
||||||
|
# remove handler
|
||||||
|
if 'remap_relative' in [hand.__name__ for hand in bpy.app.handlers.save_pre]:
|
||||||
bpy.app.handlers.save_pre.remove(remap_relative)
|
bpy.app.handlers.save_pre.remove(remap_relative)
|
||||||
|
|
||||||
keymaps.unregister()
|
keymaps.unregister()
|
||||||
|
|
Loading…
Reference in New Issue