Copy link to clipboard
Copied
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!!
Try using the: ExportOptionsWebOptimizedSVG object.
Copy link to clipboard
Copied
Try using the: ExportOptionsWebOptimizedSVG object.
Copy link to clipboard
Copied
Thanks, I am not seeing that anywhere in the reference though. Do they have that in CC 2017?
Copy link to clipboard
Copied
Yea, I see it in the OMV -
Copy link to clipboard
Copied
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!!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now