13 Replies Latest reply on Nov 28, 2018 11:53 AM by Peter Kahrel

    Error 21 for batch scripts

    el-cerezo

      Hi, everybody:

      I was trying to run several scripts at once with this simple lines of javascript

       

      app.doScript(File("/Users/… Script1.jsx"), ScriptLanguage.JAVASCRIPT);
      app.doScript(File("/Users/… Script2.jsx"), ScriptLanguage.JAVASCRIPT);
      app.doScript(File("/Users/… Script3.jsx"), ScriptLanguage.JAVASCRIPT);
      app.doScript(File("/Users/… Script4.jsx"), ScriptLanguage.JAVASCRIPT);
      app.doScript(File("/Users/… Script5.jsx"), ScriptLanguage.JAVASCRIPT);
      app.doScript(File("/Users/… Script6.jsx"), ScriptLanguage.JAVASCRIPT);
      

       

      To facilitate the reading of this post I simplified the name and the path of each script

      It runs perfect untill Script4.jsx. Indesign applies it but shows an error 21 message (undefinded is not an object), and stops the following scripts application

      When I run only Script4.jsx or the same list but one by one, there's no error message. The problem happen only when it's call from the batch script.

       

      Script4.jsx is an extended version of Green4Ever's script posted in Apply Master Page using Paragraph Style

      This are the whole lines I'm using

       

      var myDocument = app.activeDocument;
      var myParas = myDocument.stories.everyItem().paragraphs.everyItem().getElements();
      var myPage = myDocument.pages;
      for(i=0; i<myParas.length; i++)
      {
          if(myParas[i].appliedParagraphStyle.name == "Tit1")  
          {
              //Works only in CS5 and later
              myParas[i].parentTextFrames[0].parentPage.appliedMaster = myDocument.masterSpreads.item("B-master"); 
              
          }
      
       if(myParas[i].appliedParagraphStyle.name == "Tit2")  
          {
              //Works only in CS5 and later
              myParas[i].parentTextFrames[0].parentPage.appliedMaster = myDocument.masterSpreads.item("B-master");
              
          }
      
       if(myParas[i].appliedParagraphStyle.name == "Tit3")  
          {
              //Works only in CS5 and later
              myParas[i].parentTextFrames[0].parentPage.appliedMaster = myDocument.masterSpreads.item("D-master");
              
          }
      if(myParas[i].appliedParagraphStyle.name == "Tit4")  
          {
              //Works only in CS5 and later
              myParas[i].parentTextFrames[0].parentPage.appliedMaster = myDocument.masterSpreads.item("D-master");
             }
      
      }
      

       

      Extended Toolkit debugging tool show an error in line 23, but I can't realize what is about.

      I'll really appreciate any help.

      Thanks