Skip to main content
Known Participant
January 24, 2023
Question

Exporting named artboard as svg without the rest of the files contents?

  • January 24, 2023
  • 1 reply
  • 206 views

Is there a way to export an artboard as an svg but only the contents of that artboard and nothing else on the canvas/other artboards?

I had a look and seems like other people have has this issue?
Would a solution be to remove all objects/artboards except the contents of the artboard needed first?

Thanks in advance!

// Get the active document
var doc = app.activeDocument;

// Loop through all artboards in the document
for (var i = 0; i < doc.artboards.length; i++) {
  var artboard = doc.artboards[i];
  
  // Check if the artboard's name is "Backprint"
  if (artboard.name == "Backprint") {
    
    // Set the artboard as the active artboard by its index
    doc.artboards.setActiveArtboardIndex(i);

    // Get the current document's name
    var docName = doc.name.split(".")[0];
    
    // Set the export options
    var exportOptions = new ExportOptionsSVG();
    exportOptions.embedRasterImages = true;
    exportOptions.embedAllFonts = true;
    exportOptions.coordinatePrecision = 7;
    exportOptions.minify = false;
    exportOptions.cssProperties = SVGCSSPropertyLocation.STYLEELEMENTS;
    exportOptions.fontType = SVGFontType.SVGFONT;
    
    // Set the file name
    var fileName = docName + "_Backprint";
    
    // Get the current file's path
    var filePath = doc.path;
    
    // Export the artboard
    doc.exportFile(new File(filePath + "/" + fileName), ExportType.SVG, exportOptions);
    
    // Exit the loop
    break;
  }
}

 

This topic has been closed for replies.

1 reply

Mylenium
Legend
January 24, 2023

Artboards are not object containers, so no, just removing other artboards wouldn't do much. You can of course cook up all sorts of checks if an object is off-artbhoard and such and then remove them, but there's no simply function for that.

 

Mylenium