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

js executeMenuCommand('save') blocks rest of script

Community Beginner ,
Feb 05, 2017 Feb 05, 2017

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

TOPICS
Scripting

Views

499

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
Adobe
Community Beginner ,
Feb 05, 2017 Feb 05, 2017

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

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
Valorous Hero ,
Feb 05, 2017 Feb 05, 2017

Copy link to clipboard

Copied

LATEST

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() ?

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