Skip to main content
Participant
February 13, 2013
Question

ExportType.SVG "Use Artboards" option

  • February 13, 2013
  • 3 replies
  • 6646 views

I am trying to export layers to SVG, but I need to access the "Use Artboards" option in my ExportType.SVG options.  I do not see it in the Javascript reference: http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/pdf/illustrator/scripting/cs6/Illustrator-Scripting-Reference-JavaScript.pdf

Suggestions?

Thank you guys so much!

This topic has been closed for replies.

3 replies

mikaelj50294563
Participant
June 27, 2015

Hello

I found a solution for illustrator 2015, i have made a script to export different size of images for mobiles app, but i have made som changes to it to fix this problem.

You just need to run the script and export it as svg files.

i have place it on cloud app .. artbord_to_img_v2.jsx.

Hopes this helps

Participant
February 14, 2013

Ok, temporary solution:

  • Run script that exports each layer as an SVG
  • Reopen all of the SVGs, and then run a custom illustrator Action that does "Save As" with the "Use Artboards" option check on.   This purges all the hidden junk.
CarlosCanto
Community Expert
Community Expert
February 14, 2013

it works the same as if you do it manually in the UI, there's no "use artboards" option, the active artboard gets exported...so, replicated that in your script, activate the artboard you wish export first, then do Document.exportFile

Participant
February 14, 2013

In the latest version of Illustrator (CS6), there is no export as SVG.  There is "Save As" SVG, and that has the option checkbox "Use Artboards". 

Unfortunatly, there is no "Save As" method that I can find, hence the Document.exportFile.  When I run the script, it is including everything in the file, regardless of the layers or artboard position.

Here is the script:

var folder = Folder.selectDialog();

var document = app.activeDocument;

if(document && folder)

{

          var options = new ExportOptionsSVG();

          options.compressed = false;

          options.preserveEditability = false;

 

          var n = document.layers.length;

          for(var i=0; i<n; ++i)

          {

                    hideAllLayers();

                    var layer = document.layers;

                    layer.visible = true;

                    var file = new File(folder.fsName+"/"+layer.name+".png");

                    document.exportFile(file, ExportType.SVG, options);

          }

          showAllLayers();

}

function hideAllLayers()

{

          forEach(document.layers, function(layer) {

                    layer.visible = false;

          });

}

function showAllLayers()

{

          forEach(document.layers, function(layer) {

                    layer.visible = true;

          });

}

function forEach(collection, fn)

{

          var n = collection.length;

          for(var i=0; i<n; ++i)

          {

                    fn(collection);

          }

}

I might be going about this the wrong way, but it feels like I am close.  If there is someway to remove the extra pieces... maybe if I duplicate the document and delete all other layers per export? 

I am open to ideas.  Thanks!

CarlosCanto
Community Expert
Community Expert
February 14, 2013

this function is from the documentation, I checked and it is the same for CS5 and CS6, I tried it with CS5 and it works as I described in post # 1, it exports the active artboard only

// Exports current document to dest as an SVG file with specified

// options, dest contains the full path including the file name

function exportFileToSVG (dest) {

if ( app.documents.length > 0 ) {

var exportOptions = new ExportOptionsSVG();

var type = ExportType.SVG;

var fileSpec = new File(dest);

exportOptions.embedRasterImages = true;

exportOptions.embedAllFonts = false;

exportOptions.fontSubsetting = SVGFontSubsetting.GLYPHSUSED;

app.activeDocument.exportFile( fileSpec, type, exportOptions );

}

}