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

Javascript Export Options not Applied

Community Beginner ,
Nov 18, 2024 Nov 18, 2024

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();
}

  

TOPICS
Import and export , Scripting

Views

277

Translate

Translate

Report

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 3 Correct answers

Community Expert , Nov 18, 2024 Nov 18, 2024

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

Votes

Translate

Translate
Community Beginner , Nov 18, 2024 Nov 18, 2024

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. 

 

Votes

Translate

Translate
Enthusiast , Nov 19, 2024 Nov 19, 2024

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

Votes

Translate

Translate
Adobe
Community Beginner ,
Nov 18, 2024 Nov 18, 2024

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. 

Votes

Translate

Translate

Report

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
Community Expert ,
Nov 18, 2024 Nov 18, 2024

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.

Votes

Translate

Translate

Report

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
Community Beginner ,
Nov 18, 2024 Nov 18, 2024

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. 

 

Votes

Translate

Translate

Report

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
Community Beginner ,
Nov 27, 2024 Nov 27, 2024

Copy link to clipboard

Copied

LATEST

True, thank you very much

Votes

Translate

Translate

Report

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
Enthusiast ,
Nov 19, 2024 Nov 19, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Community Beginner ,
Nov 27, 2024 Nov 27, 2024

Copy link to clipboard

Copied

Thank you very much

Votes

Translate

Translate

Report

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