From 830777a280071e039c01b2f113c27aacb001605a Mon Sep 17 00:00:00 2001 From: mattmcw Date: Wed, 24 Mar 2021 09:29:30 -0400 Subject: [PATCH] Add a python utility for removing tags from svg files generated by Processing. --- processingsvg.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 processingsvg.py diff --git a/processingsvg.py b/processingsvg.py new file mode 100644 index 0000000..d6f42f6 --- /dev/null +++ b/processingsvg.py @@ -0,0 +1,43 @@ +# Find a bounding box inserted by Processing +# and remove it. Happens inconsistently. + +import sys + +argIndex = len(sys.argv) - 1 +filePath = str(sys.argv[argIndex]) + +evalLine = '' +rest = '' +i = 0 + +with open(filePath) as f : + lines = f.readlines() + for line in lines : + if i < 20 : + evalLine += line.replace('\r', '').replace('\n', '') + else : + rest += line + i += 1 + f.close() + +evalLine = evalLine.replace('>', '>\n') +lines = evalLine.split('\n') +first = True +removed = '' +clean = '' + +for line in lines: + if ' 0 : + overwrite = open(filePath, 'w') + overwrite.write(clean + rest) + overwrite.close() + print(f'File: {filePath}') + print(f'Removed: {removed}') +else : + print(f'Nothing found to remove in {filePath}') \ No newline at end of file