Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

SVG Export only visible layers

Contributor ,
Feb 01, 2017 Feb 01, 2017

I'm back! I was never leaving haha.

So I am trying to export an svg file for only the visible layer. I am able to do this manually by

Export as SVG, use artboards, and these options

When I do it this way, it only saves the visible layer. However, when I use the code below, it saves all the layers even hidden ones, and all the raster images involved.

var docRef = app.activeDocument;

var path = docRef.path;

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.coordinatePrecision = 2;

        exportOptions.fontType = SVGFontType.OUTLINEFONT;

       

        exportOptions.embedRasterImages = false;

        exportOptions.includeFileInfo = false;

        exportOptions.preserveEditability = false;

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

    }

}

exportFileToSVG('~/Desktop/blah');

If anyone has any idea why all the layers are saving and not just the visible ones, please let me know. I can always create an action by how I saved it and then run the action through the full script, but I was hoping to script everything. Thanks!!

TOPICS
Scripting
6.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Feb 01, 2017 Feb 01, 2017

Try using the: ExportOptionsWebOptimizedSVG object.

Translate
Adobe
Valorous Hero ,
Feb 01, 2017 Feb 01, 2017

Try using the: ExportOptionsWebOptimizedSVG object.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 01, 2017 Feb 01, 2017

Thanks, I am not seeing that anywhere in the reference though. Do they have that in CC 2017?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Feb 01, 2017 Feb 01, 2017

Yea, I see it in the OMV - 2017-02-01 14_19_25-Object Model Viewer.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 01, 2017 Feb 01, 2017
LATEST

Sweet. Thank you. I wish everything would be included in the javascript reference pdf.

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';

        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 appears to do what I needed. Awesome!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines