Copy link to clipboard
Copied
Hi All
I'm trying to use the executeMenuCommand to save a page of a pdf however whenever I add it to the script all the preceding lines of the script don't run at all.
Here's a simple example:
// Remove a layer from the pdf
app.activeDocument.layers.getByName('Layer 1').remove();
// Save the pdf using the menu command
app.executeMenuCommand ('save');
If I run the script without the executeMenuCommand command then 'Layer 1' is removed successfully, however if I add the executeMenuCommand line 'Layer 1' doesn't get removed but the pdf does get saved.
Any pointers as to what's happening here much appreciated, I've been testing a lot of approaches and am now stuck. Thanks
Copy link to clipboard
Copied
Think I have the solution, a redraw() is required before running the save menu command:
// Remove a layer from the pdf
app.activeDocument.layers.getByName('Layer 1').remove();
// redraw (otherwise preceding script lines are ignored)
redraw();
// Save the pdf using the menu command
app.executeMenuCommand ('save');
Alternatively if no more changes are required and the pdf can be closed then this also works:
app.activeDocument.close(SaveOptions.SAVECHANGES);
Copy link to clipboard
Copied
That's funny, I just had been compelled to post on the subject of using redraw() last night because I noticed the difference between running from ESTK and from AI. Mainly that it wouldn't work when ran from AI without the added redraw().
I'm trying to think of the execution rules at work in these situations. From your post it seems like there is a partition between the execute menu commands and regular javascript that causes it to be not synchronized unless there's a redraw() ?