Skip to main content
Participant
Nov 18, 2024 8:06 AM UTC
Answered

Javascript Export Options not Applied

I have an issue that caused me hours of troubleshooting, but I still cannot figure out why export options are not being applied to SVG files. Here is my code—if anyone has a slight clue as to what the problem is, I would greatly appreciate feedback. (In this code i even apply the options right before export but it still does not work. I also tried things like exportForScreens or saveAs and all is to no avail)
It is important to at least have 7 decimals places beeing applied.

 

// Function to export SVG using Adobe's SVG options
function getSVGOptions() {
var options = new ExportOptionsSVG();
options.embedRasterImages = true;
options.fontSubsetting = SVGFontSubsetting.None;
options.cssProperties = SVGCSSPropertyLocation.STYLEATTRIBUTES;
options.documentEncoding = SVGDocumentEncoding.UTF8;
options.DecimalPlaces = 7;
options.Minify = true;
options.Responsive = false;
return options;
}

// Function to export a single artboard as SVG, PNG, and JPG (if applicable)
function exportArtboardAsSeparateFile(doc, artboardIndex, exportFolder, baseName) {
try {
doc.artboards.setActiveArtboardIndex(artboardIndex);
var artboard = doc.artboards[artboardIndex];
var artboardName = artboard.name.replace(/_/g, "-");
var exportBaseName = baseName.replace(/_/g, "-") + "-" + artboardName;
var artboardRect = artboard.artboardRect;

// Collect items to delete outside the active artboard
var itemsToDelete = [];
for (var k = 0; k < doc.pageItems.length; k++) {
var item = doc.pageItems[k];
var itemBounds = item.visibleBounds;

if (itemBounds[0] > artboardRect[2] || itemBounds[2] < artboardRect[0] ||
itemBounds[1] < artboardRect[3] || itemBounds[3] > artboardRect[1]) {
itemsToDelete.push(item);
}
}

// Delete all items outside the artboard
for (var i = 0; i < itemsToDelete.length; i++) {
itemsToDelete[i].remove();
}

// Export SVG using Adobe's options
try {
var svgFile = new File(exportFolder + "/" + exportBaseName + ".svg");
doc.exportFile(svgFile, ExportType.SVG, getSVGOptions());
} catch (e) {
$.writeln("Error exporting SVG for artboard " + artboardIndex + ": " + e.message);
pauseForMemoryRecovery();
}

  

This topic is closed to new replies. Start a new post to keep the conversation going.
Sergey Osokin
Sergey OsokinCorrect answer
Inspiring
Nov 19, 2024 8:39 AM UTC

The fictional ChatGPT:
options.DecimalPlaces > options.coordinatePrecision
options.Minify > options.svgMinify
options.Responsive > options.svgResponsive

6 replies

Sergey Osokin
Sergey OsokinCorrect answer
Inspiring
Nov 19, 2024 8:39 AM UTC

The fictional ChatGPT:
options.DecimalPlaces > options.coordinatePrecision
options.Minify > options.svgMinify
options.Responsive > options.svgResponsive

Translate
Participant
Nov 27, 2024 1:32 PM UTC

Thank you very much

Translate
CarlosCanto
Community Expert
Community Expert
Nov 18, 2024 5:51 PM UTC

at first glance, the problem seems to be ChatGPT, it comes up with properties that do not exist in Illustrator Scripting.

Translate
Participating Frequently
Nov 18, 2024 6:00 PM UTC

Good point @CarlosCanto. As a novice that uses Chat GPT for scripting, it's important to remind it often that it's .jsx you need and not .js. 

 

Translate
Participant
Nov 27, 2024 1:33 PM UTC

True, thank you very much

Translate
Participating Frequently
Nov 18, 2024 1:50 PM UTC

Not much help here, I've not been able to successfully script my svg export. I did want to input that at my work, we have noticed a lot of changes in the last two versions in our svg exports. They had become much more sensitive to transparency issues and also were creating extraneous groups during the export, as well as how the styles were handled in the export. I read somewhere that Adobe was trying to streamline their svg export methods. That said, I'm wondering if it's possible that changes may be affecting the scripting methods and the scripting documentation was not been updated? Something to consider and hoping one of our experienced community members can shed more light. 

Translate