This repository has been archived on 2023-03-25. You can view files and clone it, but cannot push or open issues or pull requests.
mightyscape-1.1-deprecated/extensions/fablabchemnitz/attributes_editor.py
Mario Voigt 4175b377bd Refactored extension names by "rename 's/fablabchemnitz_//g' *.py;rename
's/fablabchemnitz_//g' *.inx;sed -i 's/>fablabchemnitz_/>/g' *.inx;sed
-i 's/fablabchemnitz_//g' *.py; rename 's/fablabchemnitz_//g' *.svg"
2020-09-03 00:35:27 +02:00

38 lines
1.4 KiB
Python

#!/usr/bin/env python3
import inkex
import sys
class AttribEditor(inkex.Effect):
def __init__(self):
inkex.Effect.__init__(self)
self.arg_parser.add_argument("-a", "--attributeName", help="attribute name to set")
self.arg_parser.add_argument("-v", "--attributeValue", help="attribute value to set")
self.arg_parser.add_argument("-m", "--mode", default="set", help="mode of operation")
def effect(self):
if not self.options.attributeName: # if attributeName is not given
self.OptionParser.error("Attribute name not given")
elements = self.svg.selected.values()
for el in elements:
currentAtt = el.attrib.get(self.options.attributeName)
if currentAtt is None:
currentAtt = ""
if self.options.mode == "set":
el.attrib[self.options.attributeName] = self.options.attributeValue
elif self.options.mode == "append":
el.attrib[self.options.attributeName] = currentAtt + self.options.attributeValue
elif self.options.mode == "prefix":
el.attrib[self.options.attributeName] = self.options.attributeValue + currentAtt
elif self.options.mode == "subtract":
el.attrib[self.options.attributeName] = currentAtt.replace(self.options.attributeValue, "")
elif self.options.mode == "remove":
if self.options.attributeName in el.attrib:
del el.attrib[self.options.attributeName]
else:
inkex.errormsg("Invalid mode: " + self.options.mode)
if __name__ == '__main__':
AttribEditor().run()