Skip to main content
Known Participant
May 24, 2021
Answered

export range of artboards to SVG files with names

  • May 24, 2021
  • 1 reply
  • 909 views

i got this script that allow me to export range of artboards to SVG files , but I cant find how to export each artboard with its name or an array of names 

var docRef = app.activeDocument;

var path = docRef.path;

function exportFileToSVG (dest) {

  

    if ( app.documents.length > 0 ) {

        var exportOptions = new ExportOptionsWebOptimizedSVG();

        var type = ExportType.WOSVG;

        var fileSpec = new File(dest);

    

        exportOptions.saveMultipleArtboards = true;

        exportOptions.artboardRange = '1-2';

        exportOptions.coordinatePrecision = 2;

        exportOptions.fontType = SVGFontType.OUTLINEFONT;

        exportOptions.svgMinify = true;

        exportOptions.svgId = SVGIdType.SVGIDREGULAR;

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

    }

}

exportFileToSVG('~/Desktop/blah.svg');
This topic has been closed for replies.
Correct answer femkeblanco
var ABs = app.activeDocument.artboards;
for (var i = 0; i < ABs.length; i++) {
    ABs.setActiveArtboardIndex(i);
    exportFileToSVG("~/Desktop/" + ABs[i].name + ".svg");
}
function exportFileToSVG (dest) {
    if ( app.documents.length > 0 ) {
        var exportOptions = new ExportOptionsSVG();
        var type = ExportType.SVG;
        var fileSpec = new File(dest);   
        exportOptions.saveMultipleArtboards = true;
        exportOptions.artboardRange = '1-2';
        exportOptions.coordinatePrecision = 2;
        exportOptions.fontType = SVGFontType.OUTLINEFONT;
        exportOptions.svgMinify = true;
        app.activeDocument.exportFile( fileSpec, type, exportOptions );
    }
}

1 reply

femkeblanco
Legend
May 25, 2021

What exactly is the problem? You iterate through the artboards, make each artboard active in turn and call the function with the active artboard's name added to the path. Or am I misunderstanding the question?

Known Participant
May 25, 2021

hey @femkeblanco  hope you have an amzing day , the problem is thate i wont the artboard exported with her name I misunderstanding btw 

femkeblanco
femkeblancoCorrect answer
Legend
May 25, 2021
var ABs = app.activeDocument.artboards;
for (var i = 0; i < ABs.length; i++) {
    ABs.setActiveArtboardIndex(i);
    exportFileToSVG("~/Desktop/" + ABs[i].name + ".svg");
}
function exportFileToSVG (dest) {
    if ( app.documents.length > 0 ) {
        var exportOptions = new ExportOptionsSVG();
        var type = ExportType.SVG;
        var fileSpec = new File(dest);   
        exportOptions.saveMultipleArtboards = true;
        exportOptions.artboardRange = '1-2';
        exportOptions.coordinatePrecision = 2;
        exportOptions.fontType = SVGFontType.OUTLINEFONT;
        exportOptions.svgMinify = true;
        app.activeDocument.exportFile( fileSpec, type, exportOptions );
    }
}