3 Replies Latest reply on Apr 5, 2012 10:52 AM by bdfowler00

    Script for finding character styled text and moving to particular coordinates.

    bdfowler00

      I'm pretty new to scripting and am struggling my way thorugh it.  I'm working on a project that involves moving some particular text on every page of a document to a certain area.  I've got 14 catalogs and every page has a page header at the top telling what's on that page.  Previously each one was in the middle of the top of the page.  I now want to move each one to the outer corners of the page.  They are all tagged with the same character styled called "Thick Blue Header".

       

      I found a script on these forum that I can use to move the text to a desired location.

       

      for (n=0; n<app.selection.length; n++) {

      app.selection[n].move([0.2505, 0.25]);

       

      But the problem there is it will be a different location depending on if it's on an odd or even pages.  The one above is for the even pages.  The coordinates for the odd pages are 15.6135, 0.25.

       

      So basically I'm trying to figure out how to write a script that does the following.

       

      Find text with certain character style ("Thick Blue Header") applied.

      On even numbered pages move that text to coordinates 0.2505, 0.25.

      On odd numbered pages move that text to coordinates 15.6135, 0.25.

       

      Thanks for any help you guys can give me.

        • 1. Re: Script for finding character styled text and moving to particular coordinates.
          Laubender Adobe Community Professional & MVP

          @bdfowler00 – are you really looking for odd or even numbered pages?
          OR (and then it could be a different answer) do you looking for right hand and left hand pages?

           

          If the latter, look for the "side"-property of the "page" object, if your document has facing pages:

           

          See the following example:

           

          //We only work on documents with facing pages:
          var d = app.documents[0];
          
          if(d.documentPreferences.facingPages == false){
              alert("This script will only work on documents with facing pages!");
              null;
              };
          
          //Loop through all pages:
          //Do NOT ADD pages to your doc during this loop!
          
          for(var p=0;p<d.pages.length;p++){
          
              //Looking for RIGHT hand pages:
              if(d.pages[p].side == PageSideOptions.RIGHT_HAND){
                  //Do your stuff with RIGHT hand pages
                  };
          
              //Looking for LEFT hand pages:
              if(d.pages[p].side == PageSideOptions.LEFT_HAND){
                  //Do your stuff with LEFT hand pages
                  };
          
              };
          
          • 2. Re: Script for finding character styled text and moving to particular coordinates.
            [Jongware] Most Valuable Participant

            You used a character style -- what if you add a *paragraph style* that has "away from spine" instead of the current "center" justification?

            • 3. Re: Script for finding character styled text and moving to particular coordinates.
              bdfowler00 Level 1

              Laubender - You're one the right track. I'll play around with what you're done.  The documents are 150 page catalogs (facing pages) so we are dealing with left and right pages.

               

              Jongware - The text I'm trying to move is a single text box on each page so the justification won't matter.  It's an autoparts catalog so for instaind on a page selling Steering wheels full of picture, priceing and descriptin I've got a single Text Box with the word "Steering Wheels" in it with a Character Style applied to it that makes it size 18pt and blue with white trim, etc.  Right now in the layout they are layed out in the top centerish of each page.  I've got the text box fitted to the content.  Manually, for example, on a left facing page I'm clicking on the text box and dragging it to the upper left until it hits my bleed guide lines and snaps to it.  On the left hand side it the same except I'm dragging to the top right cornor instead of the left.