Skip to main content
Participant
March 31, 2009
Question

SVG export _1_

  • March 31, 2009
  • 1 reply
  • 1629 views
Hi,
I have troubles when exporting SVG -file from Illustrator (CS3 or CS4, mac version).
Illustrator creates weird _1_, _2_ and endings to the layers, groups or items.

Like this way:
In Illustrator, I create group which name is "SB-test" (this group contains several paths).
I export SVG -file (1.1).

...then, I look that SVG -file in with text editor, Inkscape etc. application...and the "SB-test" -group ID is named as SB-test_1_

Why -and how to avoid that?

Thanks for advance!
This topic has been closed for replies.

1 reply

July 15, 2009

I know this post is fairly old, but I stumbled across the same problem with group names when converting to SVG. I created a workaround that is included in a script that is called when the SVG is loaded:

Loop through the SVG and find each group and get the name.

var svgdoc = document.embeds(0).getSVGDocument();
var groupList = svgdoc.getElementsByTagName("g");
     for(j = 0; j < groupList.length; j ++) {

       var child = groupList.item(j).getElementsByTagName("g");
       var GroupName = groupList.item(j).getAttribute("id");

Get the length of the group name and determine if the end character of the name is "_".

    var newGroupNameLength = newGroupName.length;
    var childLastChar = newGroupName.substring(newGroupNameLength-1,newGroupNameLength);

If the last character is "_", change the group name to ignore the last three characters.


    if (childLastChar == "_")  {
      newGroupName = newGroupName.substring(0,newGroupNameLength-3);
    }

set the group ID to the new group name.

    groupList.item(j).setAttribute("id",newGroupName);

Hope that helps. I use the same kind of method to correct the beginning of group names where Illustrator replaces illegal SVG starting characters such as '0' and '#' with "_x30_" and "_x23_", respectively.