Skip to main content
Participating Frequently
November 17, 2015
Answered

Can I disable redraw for file placement

  • November 17, 2015
  • 1 reply
  • 1615 views

I have a script that places some files into a place in InDesign, however it's slow because it's updating every file. I have this set

app.scriptPreferences.enableRedraw = false;

But it still updates after every placement?

This topic has been closed for replies.
Correct answer Loic.Aigon

You can't do that, what you can do is have the script close and save the id file then reopen it false and then show the window.

You have to consider 1) that you might not want the file saved in it's current state, 2) You will lose the undo / redo history, 3 The time it takes to save, close and reopen the doc.

Those considerations taken it might well be worthwhile, all depend on your workflow.

You can give it ago and see what the improvement is.

Use the filePath to reopen the doc


Hi t23gagzg‌,

Ok so I think your problem may be solved while dealing user interaction preferences. As you let native placement progress bars to appear, it does refresh the screen. So if you prevent those, you avoid refreshments and you should be good:

Let me seize this occasion to offer some improvements to your code :

var main = function(){

  //Let's store script preferences for further reset

  var sp = app.scriptPreferences.properties,

  //Set some new properties

  np = {

  //This will prevent screen refresh to the condition you…

  enableRedraw:false,

  //…set no interaction as dialogs would refresh teh screen

  userInteractionLevel:UserInteractionLevels.NEVER_INTERACT,

  },

  //A reference to our main folder

  fo,

  //a reference to a possible error

  error = false;

  //Checking if context is ok so you avoid useless processing

  if ( !app.documents.length || !app.selection.length ) return;

  //Now you cand edit preferences

  app.scriptPreferences.properties = np;

  //.parent will return a Folder Object instance or should I say a File instance of type Folder

  fo = File($.fileName).parent;

  //Calling teh secondary routine

  //try/catch will avoid script exit with script preferences not resetted.

  try {

  doPlacement ( fo );

  }

  catch(err){

  error = true;

  }

  //because it's good habit to reverse user preferences

  app.scriptPreferences.properties = sp;

  alert( error? "An error occured", "Everything went fine");

}

var doPlacement = function(folder){

  //A filter function to only retrieve PDF type files

  var pdfFilter = function(f){ return /\.pdf$/i.test(f.name); },

  //A reference to the  retrieved pdf

  pdfFile = folder.getFiles ( pdfFilter ),

  //a reference to the sum of pdf files

  n = pdfFile.length;

  //Exit if no pdf files. That will avoid further useless processing

  if ( !n ) return;

  //Attibuting first PDF File object of the array to pdfFile

  pdfFile = pdfFile[0];

  //getting selection count

  n = app.selection.length;

  //Looping through selection

  while ( n-- ) {

  //obviously you want to deal with textframes only

  if (app.selection instanceof TextFrame){

  replaceAllCharsWithFile(app.selection, pdfFile);

  }

  }

}

//a third routine to replace all characters with supplied file

var replaceAllCharsWithFile = function(textFrame, file){

  var placedFile;

  var chars = textFrame.characters;

  var n = chars.length;

  var dup;

  //removing any contents

  textFrame.contents = "";

  //looping through characters number

  while (n--) {

  if(!placedFile) {

  placedFile = textFrame.insertionPoints[0].place(file)[0];

  placedFile.fit(FitOptions.FRAME_TO_CONTENT);

  //Not sure you need to double with PROPORTIONALLY

  //as FRAME_TO_CONTENT would make the frame to adapt to the pdf image ?

  }

  else {

  //Rather than re-placing and re-fitting

  //we just duplicated the initial placed file

  placedFile.parent.parent.duplicate(LocationOptions.AT_END, textFrame.insertionPoints[-1] );

  }

  }

}

//fastEntireScript is buggy

var u;

app.doScript ( "main();", u, u, UndoModes.ENTIRE_SCRIPT );

HTH

Loic

www.ozalto.com

1 reply

Trevor:
Brainiac
November 18, 2015

Unless you have a reason not to (which you may well have) open the files with visibility set to false doc = app.open(myDoc, false);

That will make a big difference.

After your done either close the doc or add a window to it. doc.windows.add();

Loic.Aigon
Brainiac
November 18, 2015

Also disabling preflight helps