Created
December 17, 2017 11:18
-
-
Save joduplessis/5f50a5b9548f21d3d217ae70cb1c374b to your computer and use it in GitHub Desktop.
Add an auto incremented ID to each shape in an SVG file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
svgFile = 'pattern.svg' | |
svgFileNew = 'pattern1.svg' | |
with open(svgFile) as f: | |
thefile = open(svgFileNew, 'w') | |
lines = f.readlines() | |
newLines = [] | |
aiid = 0 | |
for line in lines: | |
newLine = line | |
index = line.find('/>') | |
if index != -1: | |
aiid = aiid + 1 | |
newLine = line.replace('/>', ' id="'+str(aiid)+'" />') | |
newLines.append(newLine) | |
# Write the file back | |
for line in newLines: | |
thefile.write(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment