0 Replies Latest reply on Oct 20, 2011 2:37 AM by ikitzmann

    CS5 hangs with smart text reflow during scripting

    ikitzmann

      Hello,

       

      I have a batch script that opens each input file in a folder one after another and saves them as indd and pdf.

       

      Now I have run across a problem.

       

      The script opens the input document (a special xml format for our plugin, this opens one InDesign template and places some content into a specific text frame), then run preflight to check if there are overflows etc. and then saves the content to indd and pdf.

       

      The input template has smart text reflow enabled, with adding new pages at the end of the document and deleting empty pages because I do not know how much content will be placed.

       

       

      I have some strange issues:

      In ID CS4, the script runs fine, but some times I got preflight errors for some documents (different ones on each run). If I open the documents afterwards, it seems the smart text reflow did not run before the script saved the indd (and so preflight found an text overflow).

       

      However in CS5, InDesign hangs at some time during the script - windows task manager says it is not responding. This happens at a random file (not the same each time), the first ones before came out as expected.

       

      Because of the preflight issues in CS4 I have made a test and created a new template with disabled smart text reflow and already added the maximum number of pages for my content. Now the script runs fine in CS5 (without hanging). But this way I have emtpy pages I do not want.

       

      My assumption is, that the smart text reflow does run some sort of asyncronous and gets in the way of saving/exporting to pdf the file. A "$.sleep(5000);" after opening/placing does not help either.

       

      Is there any way in scripting to force the smart text reflow or to wait for it until it is finished?

       

      Below is the relevant part of the script.

       

      Has anybody a solution or workaround?

       

      Best regards,

      Ingo

       

       

      // process documents
      for(var i = 0; i < alldocs.length; i++ ){
        try{
          // Opens document 
          // this is a format that triggers our plugin which opens a specific indt-template and places the content
          var currentDocument = app.open( alldocs[i],true);
          
          // try to force document to be really ready - TODO: is there a better/working way? Some way to wait for smart text reflow?
          currentDocument.recompose();
          //$.sleep(5000); //Fallback - sleep for a reasonable time to let the document be opened - does not help either
          
          // process the document with the selected profile
          var process = app.preflightProcesses.add(currentDocument, Settings.preflightProfile);
          process.waitForProcess();
          
          // get the results
          var preflightResults = process.aggregatedResults;
          // each report is in the [2]-Array. First condition prevents NullPointer-Errors
          if((preflightResults.length > 0) && (preflightResults[2].length>0)){
            logLine(alldocs[i].name + ': Preflight problems');
          }
          
          // save as InDesign
          var indesignFile = new File(Settings.outputDir.fullName+'/'+alldocs[i].name.replace(RegExp( '\.[^\.]{1,4}$' ), '.indd' ));
          currentDocument.save( indesignFile );
        
          // Export as PDF
          var pdfFile = new File(Settings.outputDir.fullName+ '/'+alldocs[i].name.replace(RegExp( '\.[^\.]{1,4}$' ), '.pdf' ));
          currentDocument.exportFile(ExportFormat.pdfType, pdfFile , false);
      
          currentDocument.close();
        }
        catch(err){
          // if there was a problem, note filename to display later
          logLine( alldocs[i].name + ': Errormessage was "' + err.description + '"');
        }
      }