===== Inkex (inkscape python module) ===== ==== get symbols attributes ==== === inx file === Symbol attributes extractor org.inkscape.ssm2017.symbol_attributes_extractor === python file === #!/usr/bin/env python # coding=utf-8 # # Copyright (C) 2023 ssm2017, ssm2017@gmail.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # """ This extension is getting a symbol custom attributes data-* and setting them to the object """ import inkex class SymbolAttributesExtracterExtension(inkex.EffectExtension): def effect(self): for node in self.svg.selection: # check if the node is a element if node.tag_name == "use": # get the symbol id symbol_id = node.get("xlink:href") # look for the symbol symbol = self.svg.getElementById(symbol_id) # get attributes and assign them to the for attrib_name, attrib_value in symbol.attrib.items(): if attrib_name.startswith("data-"): if not node.get(attrib_name): node.set(attrib_name, attrib_value) if __name__ == '__main__': SymbolAttributesExtracterExtension().run()