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

Javascript for using Asset Export

New Here ,
Oct 16, 2024 Oct 16, 2024

Copy link to clipboard

Copied

I'm trying to create a code that selects the whole artboard and drags it to the Asset Export to save them as svg and png. Is it possible?

TOPICS
How-to , Scripting , SDK , Tools

Views

275

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 1 Correct answer

Community Expert , Oct 16, 2024 Oct 16, 2024

Hi @placeit_1800, here is a script I wrote last year that export in various formats. Perhaps you will learn something that will help. You need to edit it to suit your needs, in particular the export paths.

- Mark

 

/**
 * Export For Screens in various formats.
 * @author m1b
 * @version 2023-03-05
 * @discussion https://community.adobe.com/t5/illustrator-discussions/script-for-export-multiple-artboard-to-jpg-png-etc/m-p/13624982
 */
(function () {

    var exportPathJPG = '~/Desktop/EXPORTS/JPG/
...

Votes

Translate

Translate
Adobe
Community Expert ,
Oct 16, 2024 Oct 16, 2024

Copy link to clipboard

Copied

Hi @placeit_1800, here is a script I wrote last year that export in various formats. Perhaps you will learn something that will help. You need to edit it to suit your needs, in particular the export paths.

- Mark

 

/**
 * Export For Screens in various formats.
 * @author m1b
 * @version 2023-03-05
 * @discussion https://community.adobe.com/t5/illustrator-discussions/script-for-export-multiple-artboard-to-jpg-png-etc/m-p/13624982
 */
(function () {

    var exportPathJPG = '~/Desktop/EXPORTS/JPG/',
        exportPathPNG = '~/Desktop/EXPORTS/PNG/',
        exportPathSVG = '~/Desktop/EXPORTS/SVG/',
        exportPathPDF = '~/Desktop/EXPORTS/PDF/';

    // Check if a document is open
    if (app.documents.length == 0) {
        alert("No open document.");
        return;
    }

    var previousInteractionLevel = app.userInteractionLevel;
    app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

    var doc = app.activeDocument;

    // do the exporting
    exportJPG(doc, File(exportPathJPG));
    exportPNG(doc, File(exportPathPNG));
    exportPDF(doc, File(exportPathPDF));
    exportSVG(doc, File(exportPathSVG));

    // clean up
    app.userInteractionLevel = previousInteractionLevel;

    // display a confirmation message
    alert("Export complete.");

    /**
     * Export all artboards as PNG.
     * @param {Document} doc - an Illustrator Document.
     * @param {Folder} [exportFolder] - the folder to export to (default: document's folder).
     */
    function exportPNG(doc, exportFolder) {

        var options = new ExportForScreensOptionsPNG24();
        options.antiAliasing = AntiAliasingMethod.ARTOPTIMIZED;
        options.scaleType = ExportForScreensScaleType.SCALEBYFACTOR;
        options.scaleTypeValue = 1;
        options.transparency = true;

        var itemToExport = new ExportForScreensItemToExport();
        itemToExport.artboards = 'all';
        itemToExport.document = false;
        exportFolder = exportFolder || doc.path;
        doc.exportForScreens(exportFolder, ExportForScreensType.SE_PNG24, options, itemToExport);

    };

    /**
     * Export all artboards as JPG.
     * @param {Document} doc - an Illustrator Document.
     * @param {Folder} [exportFolder] - the folder to export to (default: document's folder).
     */
    function exportJPG(doc, exportFolder) {

        var options = new ExportForScreensOptionsJPEG();
        options.antiAliasing = AntiAliasingMethod.ARTOPTIMIZED;
        options.compressionMethod = JPEGCompressionMethodType.BASELINESTANDARD;
        options.embedICCProfile = false;
        options.scaleType = ExportForScreensScaleType.SCALEBYFACTOR;
        options.scaleTypeValue = 1;

        var itemToExport = new ExportForScreensItemToExport();
        itemToExport.artboards = 'all';
        itemToExport.document = false;
        exportFolder = exportFolder || doc.path;
        doc.exportForScreens(exportFolder, ExportForScreensType.SE_JPEG100, options, itemToExport);

    };

    /**
     * Export all artboards as PDF.
     * @param {Document} doc - an Illustrator Document.
     * @param {Folder} [exportFolder] - the folder to export to (default: document's folder).
     */
    function exportPDF(doc, exportFolder) {

        var options = new ExportForScreensPDFOptions();
        options.pdfPreset = '[Press Quality]';

        var itemToExport = new ExportForScreensItemToExport();
        itemToExport.artboards = 'all';
        itemToExport.document = false;
        doc.exportForScreens(exportFolder, ExportForScreensType.SE_PDF, options, itemToExport);

    };

    /**
     * Export all artboards as SVG.
     * @param {Document} doc - an Illustrator Document.
     * @param {Folder} [exportFolder] - the folder to export to (default: document's folder).
     */
    function exportSVG(doc, exportFolder) {

        var options = new ExportForScreensOptionsWebOptimizedSVG();
        options.coordinatePrecision = 3;
        options.cssProperties = SVGCSSPropertyLocation.ENTITIES;
        options.fontType = SVGFontType.OUTLINEFONT;
        options.rasterImageLocation = RasterImageLocation.EMBED;
        options.svgId = SVGIdType.SVGIDREGULAR;
        options.svgMinify = false;
        options.svgResponsive = true;

        var itemToExport = new ExportForScreensItemToExport();
        itemToExport.artboards = 'all';
        itemToExport.document = false;
        doc.exportForScreens(exportFolder, ExportForScreensType.SE_SVG, options, itemToExport);

    };

})();

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
New Here ,
Oct 18, 2024 Oct 18, 2024

Copy link to clipboard

Copied

LATEST

Thank m1b!
In the end I used 

ExportOptionsSVG() and 
ExportOptionsPNG24()

Thanks for the snippet!

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