7 Replies Latest reply on Nov 19, 2015 5:39 AM by Trevorׅ

    Can I disable redraw for file placement

    t23gagzg Level 1

      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?

        • 1. Re: Can I disable redraw for file placement
          Trevorׅ Adobe Community Professional

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

          • 2. Re: Can I disable redraw for file placement
            Loic.Aigon Adobe Community Professional

            Also disabling preflight helps

            • 3. Re: Can I disable redraw for file placement
              t23gagzg Level 1

              Thanks, but this is a script that needs to be run in a working document, i.e. during editing. Is there a way to hide window then show again?

              See this script

              https://www.dropbox.com/s/rsnu2gjitduwz8o/script.zip?dl=0

              Place the script folder in your indesign scripts panel folder

              1. open the indesign file,

              2. select the text box,

              3. run the script,

               

              it updates one by one, i want it to redraw only once all the placements are completed.

              • 4. Re: Can I disable redraw for file placement
                Trevorׅ Adobe Community Professional

                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

                • 5. Re: Can I disable redraw for file placement
                  Loic.Aigon Adobe Community Professional

                  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[n] instanceof TextFrame){
                    replaceAllCharsWithFile(app.selection[n], 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

                  • 6. Re: Can I disable redraw for file placement
                    t23gagzg Level 1

                    Thank you, but maybe there is something wrong with the way Adobe forums formatted it, could you post on http://gist.github.com?

                    Error:

                    Screen Shot 2015-11-19 at 1.53.47 pm.png

                    • 7. Re: Can I disable redraw for file placement
                      Trevorׅ Adobe Community Professional

                      The , should be a :

                      Typo