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(); |
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
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
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
Copy link to clipboard
Copied
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");
}