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

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

Community Beginner ,
May 24, 2018 May 24, 2018

Copy link to clipboard

Copied

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

Views

3.3K

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 , 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"));

Votes

Translate

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

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

Copy link to clipboard

Copied

LATEST

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

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

Copy link to clipboard

Copied

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');

    }

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