3 Replies Latest reply on Jun 11, 2009 7:07 AM by Dave Saunders

    not working in CS3

    RockScript Level 1

      This code is working in Cs2 but not working in cs3 could any one tell me the code for CS3.

       

       

       

       

       

       

       

      function FigureWithoutCaption(ImgPath)   
      {
      app.findTextPreferences = app.changeTextPreferences = null
      var mycount_1=0;
      var start="<Insert ";
      var CloseTag=">"
      //var srch_cont=app.activeDocument.search(start,false,false,undefined,undefined,undefined);
      alert("Finding the image file(EPS)")
      var srch_cont=app.activeDocument.search(start,false,false,undefined,undefined,undefined);

      if(srch_cont.length>0)
      {
          for(i=srch_cont.length-1;i>=0;i--)
          {
          try{
          var Cnt=srch_cont[i].paragraphs[0].contents;
      var ImgNam=FindFileName(Cnt,start);

       


              if(ImgNam!="")
              {
              //    var len=srch_cont[i].paragraphs[0].search(start+ImgNam+CloseTag,false,false,undefined,undefin ed,undefined);
              var len=srch_cont[i].paragraphs[0].search(start+ImgNam+CloseTag,false,false,undefined,undefin ed,undefined);
                  if(len.length>0)
                  {
                      var myfile=File(ImgPath+"/"+ImgNam);
                      if(myfile.exists)
                      {
                      len[0].place(myfile);
                      mycount_1++;
                      }
                      else
                      {
                          myerrorlist=myerrorlist+"\nFigure Without Caption: "+"'"+ImgNam+"'"+" not found in the ImageFolder";
                      }
                  }
              }
             
          }
          catch(e)
          {
          foot_fig(ImgPath)   
          }
          }//for-search
      }//if
      return mycount_1

       

      }//fun

        • 1. Re: not working in CS3
          Thomas B. Nielsen Level 3

          You can make it work by putting it in another scriptfolder, try searching the forum.

           

          To make it CS3 code:

          For a start, have a look at the search examples in CS3 - you no longer search the same way as in CS2.

           

          The Find Text example from CS3:

          //FindText.jsx
          //An InDesign CS3 JavaScript
          //
          //Shows how to find text.
          //
          myCreateExampleDocument();
          //Clear the find/change preferences.
          app.findTextPreferences = NothingEnum.nothing;
          app.changeTextPreferences = NothingEnum.nothing;
          //Search the document for the string "Text".
          app.findTextPreferences.findWhat = "text";
          //Set the find options.
          app.findChangeTextOptions.caseSensitive = false;
          app.findChangeTextOptions.includeFootnotes = false;
          app.findChangeTextOptions.includeHiddenLayers = false;
          app.findChangeTextOptions.includeLockedLayersForFind = false;
          app.findChangeTextOptions.includeLockedStoriesForFind = false;
          app.findChangeTextOptions.includeMasterPages = false;
          app.findChangeTextOptions.wholeWord = false;
          var myFoundItems = app.documents.item(0).findText();
          alert("Found " + myFoundItems.length + " instances of the search string.");
          function myCreateExampleDocument(){
              //Create an example document.
              var myDocument = app.documents.add();
              //Create a text frame on page 1.
              var myTextFrame = myDocument.pages.item(0).textFrames.add();
              //Set the bounds of the text frame.
              myTextFrame.geometricBounds = myGetBounds(myDocument, myDocument.pages.item(0));
              //Fill the text frame with placeholder text.
              var myString = "This is some text. This is some more text. This is even more example text.\rThis is text in another paragraph.";
              myTextFrame.contents = myString;
          }
          function myGetBounds(myDocument, myPage){
              var myPageWidth = myDocument.documentPreferences.pageWidth;
              var myPageHeight = myDocument.documentPreferences.pageHeight
              if(myPage.side == PageSideOptions.leftHand){
                  var myX2 = myPage.marginPreferences.left;
                  var myX1 = myPage.marginPreferences.right;
              }
              else{
                  var myX1 = myPage.marginPreferences.left;
                  var myX2 = myPage.marginPreferences.right;
              }
              var myY1 = myPage.marginPreferences.top;
              var myX2 = myPageWidth - myX2;
              var myY2 = myPageHeight - myPage.marginPreferences.bottom;
              return [myY1, myX1, myY2, myX2];
          }

          1 person found this helpful
          • 2. Re: not working in CS3
            RockScript Level 1

            Thanks Thomas

            • 3. Re: not working in CS3
              Dave Saunders Level 4

              But CS2 doesn't support findTextPreferences, so while your script might work in CS2 as written here, it is not properly clearing the preferences first.

               

              What you should do is search this forum on the word "findText". That will deliver many examples of how to do searches in CS3/CS4.

               

              Dave