Add a python utility for removing <rect> tags from svg files generated by Processing.

This commit is contained in:
mattmcw 2021-03-24 09:29:30 -04:00
parent 1a881e890c
commit 830777a280
1 changed files with 43 additions and 0 deletions

43
processingsvg.py Normal file
View File

@ -0,0 +1,43 @@
# Find a <rect> 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 '<rect' in line and first:
removed += line
first = False
else :
clean += line + '\n'
if len(removed) > 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}')