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

[Q] Can we Deselect Objects by executeMenuCommand()?

Contributor ,
Aug 16, 2017 Aug 16, 2017

Copy link to clipboard

Copied

Short question:

Can we Deselect Objects by executeMenuCommand()?

Is there any way to Deselect Object(s) by ExtendScript without overwriting Undo History?

Note:

Illustrator UI operation (Control + Shift + A) does not overwrite Undo History.

But by script (app.selection = [];) does overwrite (and redo history is gone).

I could not find parameter for executeMenuCommand(), so it is not tried yet.

  ref) Illustrator CC2017 Menu Commands Reference | CC Labo

This might be related to other polygon redo issue.

  app.redo() and app.redraw() delete manually operated Polygon object's undo history

Long and detail question:

Purpose

Deselect object after Undo without overwriting Undo history

Manual operation steps: (it works)

a-1) Place circles x 10 times

a-2) Undo (Control + Z) x 5 times

   Note: One circle is selected

a-3) Deselect object (Control + Shift + A)

   Note: Selected object is deselected

a-4) Redo (Control + Z) x 5 times

Expected result: Back to after a-1)'s step

Actual result: Works fine

Script operation steps: (it does not work)

b-1) Place circles x 10 times by manually

b-2) Run following test code

Expected result: Back to after b-1)'s step

Actual result: Redo does not work

Note: if b-1) steps is done by script object is not selected, and work as expected.

I'm not sure what is good way to Deselect Objects, but I tried following 2 ways.

I think setter is triggering adding undo/redo entry.

Is there other way?

NG:

app.selection = [];

NG:

for(var i = 0; i < app.selection.length; i++){ // Same as app.selection = []

    app.selection.selected = false;

}

Test code

#target illustrator

// open document before run

/*

// Place 10 circle

for(var i = 0; i < 10; i++){

    $.writeln("polygon: " + i);

    var a = 100 + i * 20;

    activeDocument.pathItems.ellipse(-a, a, 10, 10, false, true);  // Circle

    app.redraw();

    $.sleep(1000);

}

*/

for(var i = 0; i < 5; i++){

    app.undo();

    $.writeln("undo:" + i);

    app.redraw();  // no change

    $.sleep(1000);

}

// Deselect all object

app.selection = [];  // NG: overwrite undo history: redo does not work

// NG: Following also not work

//for(var i = 0; i < app.selection.length; i++){ // Same as app.selection = []

//    $.writeln("unselect:" + i);

//    app.selection.selected = false;

//}

app.redraw();

for(var i = 0; i < 5; i++){

    app.redo();

    $.writeln("redo:" + i);

    app.redraw();

    $.sleep(1000);

}

app.redraw();

TOPICS
Scripting

Views

2.7K

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 , Aug 16, 2017 Aug 16, 2017

Hi Naoki,

We can use executeMenuCommand when we need to deselect objects like below:

app.executeMenuCommand("deselectall");

However, I don't know it behave that you want to do.

Ten

Votes

Translate

Translate
Adobe
Community Expert ,
Aug 16, 2017 Aug 16, 2017

Copy link to clipboard

Copied

Hi Naoki,

We can use executeMenuCommand when we need to deselect objects like below:

app.executeMenuCommand("deselectall");

However, I don't know it behave that you want to do.

Ten

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
Contributor ,
Aug 17, 2017 Aug 17, 2017

Copy link to clipboard

Copied

Hi Ten A​,

Thank you very much for the info.

Actually it works very well and meet my need.

So, this is same as menu command and do not overwrite undo history.

Thank you,

Naoki

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 ,
Jun 06, 2018 Jun 06, 2018

Copy link to clipboard

Copied

LATEST

Thanks for this! It seems this might be best paired with app.redraw(); at least when running through an action. I used this by itself in a function and then ran "app.executeMenuCommand("clear");" and because it didn't deselect it cleared other items inadvertently. To create a shorthand and now adding this redraw step, I created a short function that works quite well. I had also tried simply to let it sleep simply to pause and allow for a refresh, but that didn't work. Is redraw the proper method to achieve?


Function is as follows:

function aiDSA(){

     app.redraw(); //Force Illustrator to update so that it has time to catch up and deselect active things

     app.executeMenuCommand("deselectall");

}

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