3 Replies Latest reply on May 10, 2016 8:20 AM by -hans-

    change text frame options based on content paragraph style

    prtamil Level 1

      Hi Experts,

       

      I write a script to change the text frame options when that frame contains particular style(s), but I am getting error as object is invalid when I pass the 12th line. Can some one please help me to find out the error?

       

      And can some on please teach me where should I exactly find what error it is on ESTK?

       

      var mystyle=["caption"];
      for(k=0;k<mystyle.length;k++)
      {
      app.findGrepPreferences = null;
      app.changeGrepPreferences = null;
      app.findGrepPreferences.appliedParagraphStyle = mystyle[k];
      var fnd = app.findGrep();
          for (a=0; a<fnd.length; a++)
              {
                  var myTextFrame = app.selection[0].textFrames[0];
                  alert (myTextFrame);
                  myTextFrame.textFramePreferences.firstBaselineOffset=FirstBaseline.ASCENT_OFFSET;
                  myTextFrame.textFramePreferences.minimumFirstBaselineOffset=6;
                  myTextFrame.fit(FitOptions.FRAME_TO_CONTENT); 
      
      
              }
      app.findGrepPreferences = null;
      app.changeGrepPreferences = null;
      }
      
        • 1. Re: change text frame options based on content paragraph style
          -hans- Level 4

          sthg along this ... not tested

           

          var styleNames=["caption"];  //array to fill

           

          var doc = app.activeDocument;

           

          for(var p = 0; p < styleNames.length; p++)

          {

           

          app.findGrepPreferences = null;

          app.changeGrepPreferences = null;

          app.findGrepPreferences.appliedParagraphStyle = doc.paragraphStyles.itemByName(styleNames[p]);

           

          var find = app.findGrep();

          if(find.length > 0)setTFProps(find);

           

              }

           

          function setTFProps(find)

          {

           

              for(var i = 0; i < find.length; i++)

          {

              var parentTextframe = find[i].parentTextFrames[0];//assuming only one textFrame per caption

           

          with( parentTextframe)

          {

              textFramePreferences.firstBaselineOffset=FirstBaseline.ASCENT_OFFSET;

                  }

            pT.fit(FitOptions.FRAME_TO_CONTENT);

           

              }

           

              }

           

          app.findGrepPreferences = null;

          app.changeGrepPreferences = null;

          • 2. Re: change text frame options based on content paragraph style
            prtamil Level 1

            Hi -hans-

             

            it works perfectly. Can you please let me know what went wrong on coding? This will help me to learn further script writing.

             

            Thanks

            pr

            • 3. Re: change text frame options based on content paragraph style
              -hans- Level 4
              1. app.findGrepPreferences.appliedParagraphStyle = mystyle[k]; 

              this refers to a String rather than a paragraphstyle

               

              1.             var myTextFrame = app.selection[0].textFrames[0]; 

              does not take care of the searchresults, should be

              fnd[a].parentTextFrames[0];//assuming only one textFrame per caption

              1 person found this helpful