6 Replies Latest reply on Nov 25, 2009 2:48 PM by Peter Kahrel

    Move anchored frame [JS] CS4

    Fred Goldman Level 3

      Hi guys,

       

      I am really stumped over here and I was hoping someone could help me out. I wrote a script that inserts an anchored frame before each word in a story. Sometimes one will need to be deleted so I need to write a script that will then move all the following anchored frames up one word. This has proven to be very difficult.

       

      What I am doing is getting a range of text from the cursor until the end of the story:

       

      myStory = app.selection[0].parentStory;
      myIndex = app.selection[0].insertionPoints[0].index;
      myRange = myStory.characters.itemByRange(myIndex,myStory.characters[-1].index)

       

      Then I am searching that range for anchored frames:

       

      app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
      app.findGrepPreferences.findWhat = "~a";

      myFinds = myRange.findGrep()

       

      What is real puzzling is that this is returning an array of arrays. And myWord is returning the first word in the story. I don't understand what is going on here?

       

      Needlesss to say this isn't working...

       

      for(var x = myFinds[0].length-1;x>=0;x--){
          myWord  = myFinds[0][x].words[-1];
          myFinds[0][x].move(LocationOptions.atBeginning,myWord)
          }

        • 1. Re: Move anchored frame [JS] CS4
          Peter Kahrel Adobe Community Professional & MVP

          Fred,

           

          This works for me:

           

          for (var i = myFinds[0].length-1; i > 0; i--)
              myFinds[0][i].move (LocationOptions.after, myFinds[0][i-1].insertionPoints[0]);
          //move the first anchor to the beginning of the first word in myRange
          myFinds[0][0].move (LocationOptions.after, myRange.words[0].insertionPoints[0]);

           

          This one moves each anchor in myRange to the previous one. Only the first anchor needs to be targeted at a word.

           

          Peter

          • 2. Re: Move anchored frame [JS] CS4
            Fred Goldman Level 3

            Peter,

             

            This was perfect, very clever, thank you very much!

             

            Do you know why it returns an array of an array?

            • 3. Re: Move anchored frame [JS] CS4
              Harbs. Level 6

              Hmm. I just noticed that my reply disappeared into the ethers. This forum software is not very reliable...

               

              For sake of completeness this is what I wrote:

               

                  Subject:     Re: [InDesign Scripting] Move anchored frame [JS] CS4
                  From:     Harbs

                  Date:     November 25, 2009 8:34:31 AM GMT+02:00
                  To:     clearspace-649869297-226098-2-2419234@mail.forums.adobe.com

               

              Fred,

               

              I wouldn't use a grep to find the anchors. I'd use Text.textFrames (or Text.pageItems).

               

              I'd then build an array of the indexes of all the words, and move the anchored frames to the insertionPoints which correspond to those indexes.

               

              Harbs

              1 person found this helpful
              • 4. Re: Move anchored frame [JS] CS4
                Fred Goldman Level 3

                Hi Harbs!

                 

                I was actually considering that, but it seemed a little daunting . In the end I had to build an array of the geometricBounds of all the frames to resize the ones I moved so I gues it's not that difficult. (I am doing this for interlinear stuff. I am putting each piece translation in an anchored frame.)

                • 5. Re: Move anchored frame [JS] CS4
                  Harbs. Level 6

                  I figured that this was for the interlinear stuff...

                   

                  Feel free to send me an email if you want some help planning it out...

                   

                  Harbs

                  • 6. Re: Move anchored frame [JS] CS4
                    Peter Kahrel Adobe Community Professional & MVP

                    >Do you know why it returns an array of an array?

                     

                    itemBy... returns an array, so in your example, myRange is an array -- a single-element array, to be precise. findGrep() returns an array, so if you do a findGrep() (or findText()) you end up with an array of arrays. Why itemBy returns an array I don't know, that's just the way it was designed. (A while ago, figuring this out kept me off the street for a good few hours!) Probably one of these instances where understanding should be suspended and a leap of faith is needed.

                     

                    Why do you use anchored frames for interlinear glosses, by the way? Doesn't that create a load of overhead? I don't know what your interlinears look like, but I do mine without anchors without any problem. Drop me a line if you're interested.

                     

                    Peter

                    1 person found this helpful