I'm trying to use illustrator to add string or numeric data to various elements (groups,paths, etc.)

Is there a way to do this in Illustrator?

With inkscape I can use the XML Editor, it's a bit cumbersome, but it is easy and it is possible.

enter image description here

will result in...

enter image description here

  • Hi Daniel, welcome to GDSE and thanks for your question. If you want to know more about the site, please see the help center or ping one of us in the Graphic Design Chat once your reputation is sufficient (20). Keep contributing and enjoy the site!
    – Vincent
    Commented Nov 12, 2015 at 17:53

1 Answer 1


Unfortunately, InkScape is much more advanced in this regard than Illustrator. There are 3 ways, to my current understanding, that an art shape can have string data attached to it. None of them solve your question well, or nearly well as InkScape.

  1. Typing in a custom name in the layers panel for the art item will result in an id attribute. However, not all is well, as Illustrator will go ahead and convert some characters for you without so much as a polite warning. Ex: an art name of "My_Rect" resulted in an id of "My_x5F_Rect".
  2. Using the "image map" feature of the Attributes panel to input a URL string will wrap the art shape in an anchor tag, and the string appears as an xlink:href attribute of that anchor tag.
  3. Using the SVG interactivity panel, it's possible to write in some pieces of javascript and have them execute such that your custom attribute is appended via javascript when this file is opened in a browser. While this would actually be the best ("best" used here as a relative term) workaround for adding a custom data string from inside the Illustrator UI, it would certainly require javascript. However, while that is the case, it does provide a means for adding the custom string via the Illustrator UI, and it is completely within the realm of possibility that a post-export script of some kind could go through the SVG text and change up the text to yank the desired string and attribute name out of whatever format you choose, and place them as real attributes.

For example, here is an instance where I made a rectangle and assigned this function to it via SVG interactivity panel: addAttr({data_id : "my-data-id"}) The idea is that there is a javascript file to be included in this document, and it will have a function that adds this string as this attribute to this shape when loading occurs. (I selected the "onload" event from the panel's dropdown list) But, in this case, it would actually serve as a tacky temporary housing for the custom strings. And this is the resulting SVG:

<rect id="My_x5F_Rect" x="270.1" y="55.2" onload="addAttr({data_id : &quot;my-data-id&quot;})" fill="#90FFFF" stroke="#000000" stroke-miterlimit="10" width="213.3" height="213.3"/>

As you can see, it went ahead and converted the quotes to html entities also, because it's just so so helpful. So, basically, if you really had to, you could take the exported svg and use some script or even find & replace with regexps to go through the text and change addAttr({data_id : "my-data-id"}) into data_id="my-data-id" That's it, that's all I got :( And yes, they totally could stand to add some real SVG features to AI.

  • Oh, what am I saying.. if you opt for the find & replace workaround, you may as well just put whatever format is easiest, not necessarily any function, into the javascript event attribute..
    – Silly-V
    Commented Nov 12, 2015 at 0:32
  • I'm looking into making a plugin or extension, but I'm concerned that illustrator wouldn't be able to save and retrieve this data, unless it is done in some hacky way, like an invisible textfield. I saw this plugin: hotdoor.com/controlfreak/arttags that does something similar, but I don't think it exports anything.
    – Daniel
    Commented Nov 12, 2015 at 2:21
  • Looking at the art tags, I wager that it uses the Illustrator Scripting Tag, which is a data item that can be attached to art, but only through the scripting api. This "tag" is only for purposes of working inside Illustrator and have no bearing on any export , to my knowledge. Not only that, but the tags are to be written and read by the scripting api, so they're only for use withtin Illustrator and custom extension/script specifically. Can you describe your extension you want to make?
    – Silly-V
    Commented Nov 12, 2015 at 17:17
  • I picture myself having a panel that lists variables and adds ability to add, remove and edit an item. When I select any single object(or group), the panel would show the items. Sort of like inkscape does, but more user friendly (specific to this need). Additionaly, would be nice to have an option to toggle visibility, showing the values as text, so as to make inspecting values easy.On export the plugin would embed the tags as attributes of the individual objects. The amount of work to do this seems quite unreasonable though, so I may just use inkscape. I may be able to extend it easier.
    – Daniel
    Commented Nov 12, 2015 at 17:41
  • It sounds possible, but the svg export is a problem. While I would agree that it is quite an unreasonable amount of work, it still could be done through more silly hackery, using the tags and a display panel to show and edit the data and also having your extension either export the svg explicitly through a button, or somehow sense a save event, in order to immediately re-open the file as text and find/replace the id attributes with custom data. The art with tags can be temp-named by the script with appended special character, and the find/replace can look for it. But, I don't like AI export.
    – Silly-V
    Commented Nov 12, 2015 at 22:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.