Inkscape.org
Beyond the Basics add custom attribute to symbol
  1. #1
    moonmoon27 moonmoon27 @moonmoon27

    Hello,

    I have created a symbol library with several symbols. These symbols need an extra custom attribute. I use it later with different scripts, to retrieve and order symbols used in a file.

    Currently, I have to add manually an attribute in Xml editor view for each of my symbol library I use. I want to make that process more "user-friendly"

    First step would be to add the custom attribute to 'use' main tag of symbol. Unfortunately, if I add an attribute everywhere to the symbol (I tried manually in svg symbol file), it disappear when dropping the symbol on the playground.

    Is there a way to 'keep' the custom attribute?

    The ultimate solution for me would be to catch the symbol drop event, by script, and popup a window in order to enter a value for my custom attribute, I do not know if it is possible.

    Thanks for any hints,

    Claude

  2. #2
    inklinea inklinea @inklinea⛰️

    If the <use> element references the <symbol> then it will not contain any custom attributes when dropped onto the canvas.

    The simplest way to do it is to write a very small extension which toggles the attribute on the <use> element which can be triggered by a shortcut key.

    If you want to add lots of preset attributes ( like a choice of 5 for example or a list of multiple attributes ) then it might be better to add a gui to the extension.

    You cannot however capture the drag and drop event without altering the Inkscape base code.

  3. #3
    inklinea inklinea @inklinea⛰️
    def effect(self):
        pass
        
        selection_list = self.svg.selected
        if len(selection_list) < 1:
            inkex.errormsg('Please select at least one object')
            return
    
        for selection in selection_list:
            if selection.get('data-ignore'):
                selection.set('data-ignore', None)
            else:
                selection.set('data-ignore', 'True')

    Use of the keyword None without quotes causes the attribute to be removed.

    The if statement just checks for the existence of the attribute, it does not examine the value.

    If you wanted to toggle between values then you would need to use if and == 'value'

    I've attached a zipped extension which appears under Extensions>Toggle Custom Attribute

     

Inkscape Inkscape.org Inkscape Forum Beyond the Basics add custom attribute to symbol