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

How to do "Export Selection..." in Illustrator CC scripting?

Community Beginner ,
May 24, 2018 May 24, 2018

I tried app.activeDocument.selection[0].exportFile(ExportFormat.PNG, File("~/Desktop/temp/1.png"), false);

but it says exportFile is not a function in ExtendedScript.

TOPICS
Scripting
3.6K
Translate
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 , May 25, 2018 May 25, 2018

if you're using the latest CC version, use this line

app.activeDocument.exportSelectionAsPNG(File("c:/temp/selection.png"));

Translate
Adobe
Participant ,
May 25, 2018 May 25, 2018

function exportFile is only for activeDocument, and yet - swap the format and path

// app.activeDocument.exportFile(exportFile, exportFormat [, options])

app.activeDocument.exportFile(File("~/Desktop/temp/1.png"), ExportFormat.PNG);

Translate
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 ,
May 25, 2018 May 25, 2018

I tried this and it exports entire artboard, including all the objects. How do we export only selected object instead?

Translate
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 ,
May 25, 2018 May 25, 2018

if you're using the latest CC version, use this line

app.activeDocument.exportSelectionAsPNG(File("c:/temp/selection.png"));

Translate
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 ,
May 25, 2018 May 25, 2018
LATEST

Yes~ it's really a clean way to do it. Thanks 😃

Translate
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
Participant ,
May 25, 2018 May 25, 2018

I do export at so:

if (selection.length) {

    // png options

        var ex = new ExportOptionsPNG24(),

            exType = ExportType.PNG24,

            file = new File("~/Desktop/1.png"),

            isReplaceFile = false;

        ex.artBoardClipping = true;

    if (file.exists) {

        isReplaceFile = confirm('Replace file - "' + file.toString().replace(file.path, '').slice(1) + '"');

    }

        else {

            isReplaceFile = true;

        }

    if (isReplaceFile) {

        // run fit artboard to selection

            activeDocument.artboards[activeDocument.artboards.getActiveArtboardIndex()].artboardRect = selection[0].visibleBounds;

        // export

            app.activeDocument.exportFile(file, exType, ex);

        // reset - fit artboard to selection

            app.undo();

    }

}

    else {

        alert('Please select an object');

    }

Translate
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