5 Replies Latest reply on Apr 24, 2013 10:51 PM by rajnikids

    Anchoring textFrame

    rajnikids Level 1

      Hi Forum,

       

      I tried to create and anchor the textFrame, before the word ("WHAT IS COVERED."), which I find...

       

      But the anchored text Frame is inserted at the end of the text or at the beginning of the next paragraphs, which i find (""WHAT IS COVERED."). (screenshot attached for referencing the false place)

       

      Could can body fix this... Pls.

       

      here is my code.....

       

      myDocument = app.activeDocument;

      var nF = app.activeDocument.textFrames.add()

      nF.geometricBounds = [50,50,30,30];

      try {

          var myOStyle = myDocument.objectStyles.item("LeftAlign");

          myOStyle.name;

      } catch (e) {

          var myOStyle = myDocument.objectStyles.add({name: "LeftAlign"});

      }

      nF.applyObjectStyle(myOStyle)

      app.select(nF);

      app.cut();

      //app.cut();

      app.findGrepPreferences.findWhat = "What is covered.";

      found = app.findGrep();

      for (i=0; i<found.length; i++) {

          fnd = found[i]

          sel = app.select(fnd);

      mySourceFrame = app.activeDocument.pages.item(0).textFrames.item(0).parentStory.paragraphs.everyItem();

      app.paste(LocationOptions.AT_BEGINNING, fnd.insertionPoints[0]);

      }

       

      Advance thanks & regards,

      rkids...anchor.png

        • 1. Re: Anchoring textFrame
          [Jongware] Most Valuable Participant

          (Without trying)

           

          Is this perhaps because you are changing the text by inserting the text frame, and therefore from the first one off, all "next" stored FindGrep occurrences are invalid? If so, your very first inserted text frame would be in the correct position; the next off by one character, then off by two, etc.

           

          Try with this instead:

           

          found = app.findGrep(true);
          

           

          meaning the resulting array is in last-to-first order. Changing the last item first will not mess up the rest of the array.

          • 2. Re: Anchoring textFrame
            Trevorׅ Adobe Community Professional

            Hi rkids,

             

            Oh dear, oh dear, oh dear, sigh, sigh, sigh

             

            2 points..

            1) In scripting it is very rare that you have to select, copy and paste, your's is certainly not one of them.

            2) After 80 posts it is about time that you learnt how to format your scripts on the forum, it makes them easier to read. See screenshots.

            Adobe Community_ Anchoring textFrame_2013-04-25_02-14-18.png

            Adobe Community_ Reply to 'Anchoring textFrame'_2013-04-25_02-15-06.png

             

             

            Anyway this is more or less the correct way to do what you want.

             

            var myDocument = app.activeDocument;
            var myOStyle = (myDocument.objectStyles.item("LeftAlign").isValid) ? myDocument.objectStyles.item("LeftAlign") : myDocument.objectStyles.add({name: "LeftAlign"});
            app.findGrepPreferences = app.changeGrepPreferences = null;
            app.findGrepPreferences.findWhat = "What is covered.";
            var myFinds = myDocument.findGrep();
            l = myFinds.length;
            while (l--) myFinds[l].insertionPoints[0].textFrames.add({geometricBounds: [50,50,30,30], appliedObjectStyle: myOStyle}) // IMPORTANT LOOP BACKWARDS!!!
            

             

            Note also that you don't have to declare a varible for the textframe and then give its dimention and then its object style, you can do it all in one shot.

             

            Regards

            Trevor

             

            P.s. Sorry for being somewhat condescending.

            • 3. Re: Anchoring textFrame
              Trevorׅ Adobe Community Professional

              Hi Jongware,

               

              Didn't see you there,

              You are so much kinder than me.

              • 4. Re: Anchoring textFrame
                Trevorׅ Adobe Community Professional

                Ok

                I see from your screenshot that you have cs3 so you can't use isValid to test for the object style so you should use the try catch in the way you did

                • 5. Re: Anchoring textFrame
                  rajnikids Level 1

                  Waugh!,

                   

                  As sir ~Trevor~ said,

                  I dont know the methods of updating screenshot.. sorry for that... and thanks for what I have learnt from you sir..... Definately a new learnings...

                   

                  Hi Jongware!...thanks for your patience of reading such a long and ugly script, which I produced, instead of directly asking for help!... Please bare with this, as im the beginner, still...

                   

                  Sir (Jongware & Trevor) I will test this in CS5.5 and let you know, if any problem..

                   

                  Please help me in my future request to understand more about the concept of Anchor objects.

                   

                  thanks so much for your kindness post..