From 323ad11cceaa3677f9cb8c6012c05c6260db4eb2 Mon Sep 17 00:00:00 2001 From: Geoff Sokoll Date: Sat, 1 Jan 2022 14:37:36 +1000 Subject: [PATCH 1/3] Update ExportCommand.py Add "slugify" method to sanitise filenames (removing haracters that aren't alphanumerics, underscores, or hyphens, and strip leading and trailing whitespace, dashes, and underscores). --- Project-Archiver/commands/ExportCommand.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Project-Archiver/commands/ExportCommand.py b/Project-Archiver/commands/ExportCommand.py index 2a7a440..78d484f 100644 --- a/Project-Archiver/commands/ExportCommand.py +++ b/Project-Archiver/commands/ExportCommand.py @@ -131,8 +131,27 @@ def get_name(write_version, option): else: raise ValueError('Something strange happened') + # replace invalid characters in filename + output_name = slugify(output_name) + return output_name +# Inspired by https://stackoverflow.com/questions/295135/turn-a-string-into-a-valid-filename +def slugify(value, allow_unicode=False): + """ + Taken from https://github.com/django/django/blob/master/django/utils/text.py + Convert to ASCII if 'allow_unicode' is False. Convert spaces or repeated + dashes to single dashes. Remove characters that aren't alphanumerics, + underscores, or hyphens. Convert to lowercase. Also strip leading and + trailing whitespace, dashes, and underscores. + """ + value = str(value) + if allow_unicode: + value = unicodedata.normalize('NFKC', value) + else: + value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii') + value = re.sub(r'[^\w\s-]', '', value) + return re.sub(r'[-\s]+', '-', value).strip('-_') def update_name_inputs(command_inputs, selection): command_inputs.itemById('write_version').isVisible = False From a908630325fadf339672f8e373a4856764d39f42 Mon Sep 17 00:00:00 2001 From: Geoff Sokoll Date: Sat, 7 Oct 2023 12:48:17 +1000 Subject: [PATCH 2/3] Update ExportCommand.py --- Project-Archiver/commands/ExportCommand.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Project-Archiver/commands/ExportCommand.py b/Project-Archiver/commands/ExportCommand.py index 78d484f..2801729 100644 --- a/Project-Archiver/commands/ExportCommand.py +++ b/Project-Archiver/commands/ExportCommand.py @@ -6,6 +6,7 @@ # This file is a component of Project-Archiver. ~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ import os +import unicodedata import adsk.core import adsk.fusion From 6a428f63b5b1724ad4e8996c51fce229a65d5dc7 Mon Sep 17 00:00:00 2001 From: Geoff Sokoll Date: Sat, 7 Oct 2023 13:02:53 +1000 Subject: [PATCH 3/3] Update ExportCommand.py --- Project-Archiver/commands/ExportCommand.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Project-Archiver/commands/ExportCommand.py b/Project-Archiver/commands/ExportCommand.py index 2801729..f49881e 100644 --- a/Project-Archiver/commands/ExportCommand.py +++ b/Project-Archiver/commands/ExportCommand.py @@ -49,7 +49,9 @@ def export_folder(root_folder, output_folder, file_types, write_version, name_op except AttributeError as e: ao.ui.messageBox(str(e)) break - + + # close current doc + ao.app.activeDocument.close(False) def open_doc(data_file): app = adsk.core.Application.get()