Copy link to clipboard
Copied
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();
}
at first glance, the problem seems to be ChatGPT, it comes up with properties that do not exist in Illustrator Scripting.
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.
The fictional ChatGPT:
options.DecimalPlaces > options.coordinatePrecision
options.Minify > options.svgMinify
options.Responsive > options.svgResponsive
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
at first glance, the problem seems to be ChatGPT, it comes up with properties that do not exist in Illustrator Scripting.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
True, thank you very much
Copy link to clipboard
Copied
The fictional ChatGPT:
options.DecimalPlaces > options.coordinatePrecision
options.Minify > options.svgMinify
options.Responsive > options.svgResponsive
Copy link to clipboard
Copied
Thank you very much