11 Replies Latest reply on Jun 3, 2014 7:29 PM by hasvi

    How to insert "Anchroed Object"

    hasvi Level 1

      I need to find the all 'italic' words in my Indesign file by using below code:

       

       

      app.findTextPreferences.appliedCharacterStyle= "Italic";

       

       

      Now I want to insert the 'Anchore Object' before the Italic word, that anchore object width must be match with italic word width, and it that anchored box should be placed on italic words, is this possible by script?

      FYI as like below:

      1.png

       

       

      by

      hasvi

        • 1. Re: How to insert "Anchroed Object"
          Laubender Adobe Community Professional & MVP

          @Hasvi – to answer the title of your thread: in this case – your screenshot – I would create a rectangle at the first insertion point of the found text with the rectangles.add() method.

           

          Or: have an anchored rectangle already positioned in the document and duplicate the character that is representing this anchored rectangle from one text frame to the first insertion point of the found text.

           

          Increase or decrease its width accordingly to the distance the horizontalOffset of the first and last insertionPoint of your found text.

           

          Loop through the found text from back to forth.

           

          Uwe

          • 2. Re: How to insert "Anchroed Object"
            csm_phil Level 4

            Hi hasvi,

             

            As per UWE instructions I write the script. try this one.

             

            First, create the object style as per your requirement base.

            Untitled.png

             

             

            var myDoc = app.activeDocument;
            app.findTextPreferences.appliedCharacterStyle= "italic";
            var myFind = app.findText();
            for(i=0; i<myFind.length; i++){
                var myTxt = (myFind[i].texts[0]);
                if(myTxt.lines.length ==1){
                    var myDup = myTxt.createOutlines(false);
                    var myGeo = myDup[0].geometricBounds;
                    var myTF = myTxt.insertionPoints[0].rectangles.add({geometricBounds:myGeo});
                    myDup[0].remove();
                    myTF.appliedObjectStyle = myDoc.objectStyles.item("TESTING");
                    }
                }
            
            

             

             

            thx,

            csm_phil

            • 3. Re: How to insert "Anchroed Object"
              hasvi Level 1

              Hi csm_phil,


              Thanks for your help, Everything is fine,

              After script:

              1.png

              now I need to add +2 points (both: height & Width ) for pink color box, and it has to set on italic text as like below.

              My requirement:

              2.png

              by

              hasvi

              • 4. Re: How to insert "Anchroed Object"
                Laubender Adobe Community Professional & MVP

                As I already said: loop from back to forth. Maybe these issues are gone then.
                Because adding a rectangle is adding a character! And doing that is doing something to the found text.

                 

                What i cannot see from your screenshots is where these anchors are exactly positioned.
                Turn on "Show Hidden Characters" and do another screenshot, please…

                 

                Uwe

                • 5. Re: How to insert "Anchroed Object"
                  hasvi Level 1

                  Hi,

                  see this

                   

                  1.png

                  by

                  hasvi

                  • 6. Re: How to insert "Anchroed Object"
                    Laubender Adobe Community Professional & MVP

                    Is the blank character in front of "participation" also formatted as "italic"?
                    If yes, you have a problem with calculating position of the rectangle.

                     

                    You could check, if the found text has white space at the beginning and/or at the end. And calculation the width of the rectangle only considering the horizontalOffset values on that. Also you could move the anchor character after the white space in front of the italic word.

                     

                    Did you loop from back to forth?

                     

                    Uwe

                    • 7. Re: How to insert "Anchroed Object"
                      hasvi Level 1

                      Hi,

                       

                      Again I have check with new file, I try to fix the anchor mark through the object style but I cant, because the anchor mark moving backwards, see the snapshot:

                       

                      1.png

                      see my LDF object style setting also.

                      2.png

                       

                      by

                      hasvi

                      • 8. Re: How to insert "Anchroed Object"
                        Laubender Adobe Community Professional & MVP

                        @Hasvi – what is your position relative to?
                        Your screenshot says: "X Relative To: Text Frame".


                        There are other options like: "X Relative To: Anchor".

                        And set: "X Offset: 0 in".

                         

                        In scripting terms:

                         

                        myRectangle.anchoredObjectSettings.horizontalReferencePoint = AnchoredRelativeTo.ANCHOR_LOCATION;

                        myRectangle.anchoredObjectSettings.anchorXoffset = 0;

                         

                        Uwe

                        • 9. Re: How to insert "Anchroed Object"
                          hasvi Level 1

                          Hi Ume,

                           

                          I have correct the anchor position, now its ok, but that insert position of Anchored object is incorrect, 'insert position' is going backward. as like below:

                          1.jpg

                          by

                          hasvi

                          • 10. Re: How to insert "Anchroed Object"
                            Laubender Adobe Community Professional & MVP

                            That's why I asked in what direction your loop on the found text is going.

                            From last to first index? Or from first to last index?

                             

                            //Forward loop:

                            for(var n=0; n<myFoundText.length; n=n+1){};

                             

                            //Backward loop:

                            for(var n=myFoundText.length-1; n>=0; n=n-1){};

                             

                            Uwe

                            • 11. Re: How to insert "Anchroed Object"
                              hasvi Level 1

                              Thanks for your excellent job Ume