Skip to main content
Participant
November 5, 2012
Answered

Enfocus Switch and indesign Script (JavaScript CS5.5)

  • November 5, 2012
  • 1 reply
  • 2407 views

I was on here last night asking for help with a center all images/graphics code and got terrific feedback.

Now I have a new problem with the same scrpit, Below is a script that I wrote for relinking broken links. It works like a champ exept when the orignal image/graphic is not the same size of the existing new link. So I added a new part to the code (what i had help with last night) I have bolded the sectioin. 

When I run the scrpit in Indd everything works great. But, when I run the script throught Enfocus Switch the program stalls

AnyIdeas or sugestions are greatly appreciated.

//////Code Starts Here//////////

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

var docs = app.documents;

for (var i = 0; i < docs.length; i++) {

     UpdateAllOutdatedLinks(docs);

}

function UpdateAllOutdatedLinks(doc) {

     for (var d = doc.links.length-1; d >= 0; d--) {

          var link = doc.links;

          if (link.status == LinkStatus.linkOutOfDate) {

               link.update();

          }

     }

}

app.activeDocument.pages.everyItem().rectangles.everyItem().images[0]. fit(FitOptions.CEN TER_CONTENT);

//////// Code Ends Here ////////

This topic has been closed for replies.
Correct answer Jump_Over

Hi,

If "Enfocus Switch" is a 3rd party task manager Trevor's advice to add

#target indesign

definitelly helps to run.

I would modify:

  • docs.pages.everyItem().rectangles.everyItem().images[0]. fit(FitOptions.CENTER_CONTENT);

          should be inside your for_loop (docs).
          (Centering resized images is good enough for you?)

  • app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

           you should go back to interacting at script's end, I guess.

Jump_Over

1 reply

Trevor:
Legend
November 5, 2012

Hi again Paul,

I don't know what you mean by "Enfocus Switch " do you mean throw the ESTK script editors run?

If so you probably have it set to ExtendedScript Tool Kit.

You can change it manually, or better to include this line at the begging of the script

#target indesign

After rereading your post I highly doubt that this is the solution, but you can try and if not then you can clarify what you mean by the enfocus script.

See also annotations below

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

var docs = app.documents;

for (var i = 0; i < docs.length; i++) { // this "docs" is for all the open documents

     UpdateAllOutdatedLinks(docs);

}

function UpdateAllOutdatedLinks(doc) { // You have not declared "doc" without the "s"

     for (var d = doc.links.length-1; d >= 0; d--) {

          var link = doc.links;

          if (link.status == LinkStatus.linkOutOfDate) {

               link.update();

          }

     }

}

app.activeDocument.pages.everyItem().rectangles.everyItem().images[0]. fit(FitOptions.CEN TER_CONTENT);

// this is the active document

Regards

Trevor

Jump_Over
Jump_OverCorrect answer
Legend
November 5, 2012

Hi,

If "Enfocus Switch" is a 3rd party task manager Trevor's advice to add

#target indesign

definitelly helps to run.

I would modify:

  • docs.pages.everyItem().rectangles.everyItem().images[0]. fit(FitOptions.CENTER_CONTENT);

          should be inside your for_loop (docs).
          (Centering resized images is good enough for you?)

  • app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

           you should go back to interacting at script's end, I guess.

Jump_Over

Participant
November 6, 2012

Thanks for your help everything is working again!!