I have an Illustrator file with upwards of 50 groups on one layer and one artboard. The groups are laid out like tiles in the file. The idea is that we export each tile individually and reassemble on the front-end of the site. In order to do that I need to be able to export each “tile” along with a few pieces of arbitrary information. These SVGs will be exported for use on the front-end of a site.
So far I’ve written a script that:
- outlines all text and moves each group onto its own layer;
adds a
textFrame
to the layer containing this text:{ "name": "layer_name", "dimensions": { "top": 0, "left": 1306, "width": 278, "height": 312 } }
and moves each layer to a new artboard, resizing the artboard to the size of the art;
This gets me set up just right for exporting every artboard as a separate SVG. I put the text in place because my original plan was to include it in the SVG and read it from the textFrame in the front-end so I can set the position of the tile correctly, then I would destroy or hide the textFrame
.
But now I’m wondering, is it possible to include this kind of information inside the SVG when exported? Maybe as a data-
attribute? Or something else?
Updates:
- It was recommended that I use an XML namespace instead of a data-attribute as they’re really more for HTML. How can I programmatically add XML nodes to an SVG on export?
- I’m also looking into
variables
anddataSets
as it seems you can include these with the SVG export.