Inkscape.org
Beyond the Basics How to add a Title to Symbols in a Symbol file
  1. #1
    meetdilip meetdilip @meetdilip

    This entry didn't have any title in the symbol file. I added

      <title id="pound gbp">GBP Currency Pound</title>

    But there are around 1000 + symbols like this in the sprite file. Is there any way to automate this process and make titles available inside Inkscape while using Symbols. Also because we can search Titles inside the Symbols window. I got the name from " class " value. Thanks.

     

    <symbol
           id="symbol16060"
           width="16"
           height="16"
           fill="currentColor"
           class="bi bi-currency-pound"
           viewBox="0 0 16 16">
            <title id="pound gbp">GBP Currency Pound</title>
          <path
             d="M4 8.585h1.969c.115.465.186.939.186 1.43 0 1.385-.736 2.496-2.075 2.771V14H12v-1.24H6.492v-.129c.825-.525 1.135-1.446 1.135-2.694 0-.465-.07-.913-.168-1.352h3.29v-.972H7.22c-.186-.723-.372-1.455-.372-2.247 0-1.274 1.047-2.066 2.58-2.066a5.32 5.32 0 0 1 2.103.465V2.456A5.629 5.629 0 0 0 9.348 2C6.865 2 5.322 3.291 5.322 5.366c0 .775.195 1.515.399 2.247H4v.972z"
             id="path1872-3" />
        </symbol>

     

     

  2. #2
    meetdilip meetdilip @meetdilip

    @TylerDurden  hi, is there any way to change the topic title. I should have used " How to add a Title to Symbols in a Symbol file ". Perhaps the wrong title is keeping this thread idle. Thanks.

  3. #3
    inklinea inklinea @inklinea⛰️

    Yes, but it requires writing a script to do so. There isn't a feature in Inkscape which would do this automatically.

    I would do this without using Inkscape at all.

    You might have some luck if you can find an XML editor which has advanced tag features ( similar to mp3 tagging ) 

    For a single file it's very easy to do in javascript in web browser. 

    An example : 

    If you open your svg file in a browser such as Chrome and press F12 to bring up the development console

    These three lines will demonstrate how to update for a single symbol ( the first one found )

    var className = document.getElementsByTagName('symbol')[0].getAttribute('class')

    document.getElementsByTagName('symbol')[0].setAttribute('Title', className)

    console.log(document.getElementsByTagName('svg')[0])

    A loop for the above is what you need.  If you expand the code that console.log outputs, you will see the first symbol will have a title.

     

  4. #4
    meetdilip meetdilip @meetdilip

    Thanks +TylerDurden +inklinea

     

    I will try to find some method to execute this JS in a loop.

     

    inklinea

    You might have some luck if you can find an XML editor which has advanced tag features ( similar to mp3 tagging ) 

     

    I have VS Code. Will it have any plugin that can be used to achieve this ? So nice of you to help.

  5. #5
    meetdilip meetdilip @meetdilip
    *

    @inklinea got some help. Sadly, I am not able to use it

     

    var input = document.getElementsByTagName("input");
                alert(input.length);

     

    for(let i = 0;i < input.length; i++)
    {
        ShowResults(input[i].value);
    }


    for(let i = 0;i < input.length; i++)
    {
        ShowResults(input[i].value);
    }

    var className = document.getElementsByTagName('symbol')[0].getAttribute('class')


    var input=document.getElementsByTagName('symbol');

    for(let i = 0;i < input.length; i++)
    {
        document.getElementsByTagName('symbol')[i].setAttribute('Title', className);

    }

     

    put ur code in place of showresults above

    and use i instead of 0

  6. #6
    meetdilip meetdilip @meetdilip

    Ok, looks like I managed to add a title to every <symbol>

    But when I use this inside Inkscape 1.0 as Symbol it says " without a title ". It would be nice to know what is wrong. Have I not added a title the right way ? If not, please guide. Thanks.

     

      <symbol
         id="arrow-clockwise"
         width="16"
         height="16"
         fill="currentColor"
         class="bi bi-arrow-clockwise"
    title="arrow-clockwise"
         viewBox="0 0 16 16">
        <path
           fill-rule="evenodd"
           d="M8 3a5 5 0 1 0 4.546 2.914.5.5 0 0 1 .908-.417A6 6 0 1 1 8 2v1z"
           id="path77" />
        <path
           d="M8 4.466V.534a.25.25 0 0 1 .41-.192l2.36 1.966c.12.1.12.284 0 .384L8.41 4.658A.25.25 0 0 1 8 4.466z"
           id="path79" />
      </symbol>

  7. #7
    inklinea inklinea @inklinea⛰️

    Apologies, my fault. 

    The code I posted was to create an attribute called title. 

    var className = document.getElementsByTagName('symbol')[0].getAttribute('class')

    var sym = document.createElement('title')

    sym.innerHTML = className

    document.getElementsByTagName('symbol')[0].appendChild(sym)

     

    I might write something in python as an inkscape extension in the future. 

    Paths > symbol etc is something that I have definitely used in the past.


    console.log(document.getElementsByTagName('svg')[0])

  8. #8
    meetdilip meetdilip @meetdilip

    Thanks @inklinea , all Looking forward to your Python based script :)

     

    I somehow managed to add <title> properly to my Symbol pack. I just finished doing the same and got this notification for the above post. Lots of hard work and a lot of people helped 🏆

Inkscape Inkscape.org Inkscape Forum Beyond the Basics How to add a Title to Symbols in a Symbol file