Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion Project-Archiver/commands/ExportCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# This file is a component of Project-Archiver. ~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import os
import unicodedata

import adsk.core
import adsk.fusion
Expand Down Expand Up @@ -48,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()
Expand Down Expand Up @@ -131,8 +134,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
Expand Down