9 Replies Latest reply on Jul 25, 2016 6:22 AM by selvam214

    Anchor mark position

    selvam214 Level 1

      Hi All,

      I want to check the anchor marker position inside paragraph. If 1st character of paragraph or last character of paragraph, no issue. But the anchor character placed middle of the paragraph or middle of the word it should be generate the report.

       

      I have achieved some steps here, kindly help to complete my target.

       

      main (); 

      function main (){ 

          app.findGrepPreferences = NothingEnum.NOTHING; 

          app.findGrepPreferences.findWhat = "~a"; 

          var objectsArray = app.activeDocument.findGrep(); 

          for (var c = 0; c < objectsArray.length; c++) { 

              if (objectsArray[c].textFrames.length > 0){

                  var targetTextFrame = objectsArray[c].textFrames.item(0);

                  var textFramePosition = targetTextFrame.anchoredObjectSettings.anchoredPosition;

                  if (textFramePosition == AnchorPosition.ANCHORED){

                      objectsArray[c].words[0].select();

                      if(objectsArray[c].paragraphs[0].characters[0]==true) {

                          //lacked from this

                          }

                      }

                  }

          } 

      }

       

       

       

      Wrong position:

      Screen Shot 2016-07-21 at 3.47.22 pm.png

       

       

      No issue for correct position:

       

      Screen Shot 2016-07-21 at 3.47.35 pm.png

       

       

      Thanks in advance,

      Selva

        • 1. Re: Anchor mark position
          karthiks94217840 Level 2

          Hi,

           

          Try it below code all options (anchoredObjectSettings):

           

          myTextframe.anchoredObjectSettings.anchoredPosition = AnchorPosition.ANCHORED;

          myTextframe.anchoredObjectSettings.anchorPoint = AnchorPoint.BOTTOM_LEFT_ANCHOR;

          myTextframe.anchoredObjectSettings.horizontalAlignment = HorizontalAlignment.LEFT_ALIGN;

          myTextframe.anchoredObjectSettings.horizontalReferencePoint = AnchoredRelativeTo.TEXT_FRAME;

          myTextframe.anchoredObjectSettings.anchorXoffset = "30p";

          myTextframe.anchoredObjectSettings.anchorYoffset = "36p";

          myTextframe.textWrapPreferences.textWrapMode = TextWrapModes.BOUNDING_BOX_TEXT_WRAP; 

          myTextframe.textWrapPreferences.textWrapOffset = new Array (".5p", 0, ".5p", 0)

           

           

          Thanks

          • 2. Re: Anchor mark position
            Trevorׅ Adobe Community Professional

            What's wrong about the wrong position?

            • 3. Re: Anchor mark position
              selvam214 Level 1

              Hi Trevor,

              The anchor marker placed inside the text, this is the wrong position.

              Screen Shot 2016-07-21 at 3.47.22 pm.png

               

               

               

              The below method is correct?

               

              main (); 

              function main (){ 

                  var myResult=[];

                  app.findGrepPreferences = NothingEnum.NOTHING; 

                  app.findGrepPreferences.findWhat = "~a"; 

                  var objectsArray = app.activeDocument.findGrep(); 

                  for (var c = 0; c < objectsArray.length; c++) { 

                      if (objectsArray[c].textFrames.length > 0){

                          var targetTextFrame = objectsArray[c].textFrames.item(0);

                          var textFramePosition = targetTextFrame.anchoredObjectSettings.anchoredPosition;

                          if (textFramePosition == AnchorPosition.ANCHORED){

                              var myAncPos = objectsArray[c].characters[0];

                              var myPara = objectsArray[c].paragraphs[0].characters;

                              var myLast = myPara[-2];

                              var myFrist = myPara[0];

                              if((myAncPos!=myFrist)||(myAncPos!=myLast))

                              {

              //~                     myResult.push(myAncPos.parentTextFrames[0].parentPage.name);

                                  myResult.push(myAncPos.parentTextFrames[0].parentPage.name);

                                  }

                              }

                          }

                  } 

              alert(myResult);

              }

               

               

               

              Thanks,

              Selva

              • 4. Re: Anchor mark position
                Trevorׅ Adobe Community Professional

                Ok I understand you now.

                I've got to do some work now but if no one provides an answer by Sunday I'll try do it then.

                • 5. Re: Anchor mark position
                  selvam214 Level 1

                  Thanks Trevor.

                  • 6. Re: Anchor mark position
                    selvam214 Level 1

                    Hi All,

                    Kindly help on this topic.

                     

                     

                    Selva

                    • 7. Re: Anchor mark position
                      [Jongware] Most Valuable Participant

                      You were rather close, but you went the wrong way with the line

                       

                      if (objectsArray[c].textFrames.length > 0)

                       

                      The anchored object itself can contain text frames (inside) – but that's not what you should be looking at. You should look at the found item, which is the anchored object you are looking for.

                       

                      As an anchored object is a simple "character", you can immediately read its 'index', the linear position inside its parent story. Since you want to know its distance from the start of its parent paragraph, you can walk up the hierarchy of objects and check it against the index of its "paragraphs[0]", which is the index of the first character of that paragraph. Checking against the end of a paragraph can be done the same way, against this paragraph's length, except that you need to allow for minus 1 character for the anchored object itself, and minus 1 character for the final hard return. (It is possible that the paragraph you are checking does not end with a hard return, for instance at the end of a story or in a footnote or table cell. If those are possible and you want to correctly check in all cases, add some lines to see if the last character is a hard return.)

                       

                      This is what I end up with:

                       

                      app.findGrepPreferences = NothingEnum.NOTHING;
                      app.findGrepPreferences.findWhat = "~a";
                      var objectsArray = app.activeDocument.findGrep();
                      for (var c = 0; c < objectsArray.length; c++)
                      {
                      position = objectsArray[c].index - objectsArray[c].paragraphs[0].index;
                      if (position > 0 && position < objectsArray[c].paragraphs[0].length-2)
                        alert (position);
                      }
                      
                      • 8. Re: Anchor mark position
                        Laubender Adobe Community Professional & MVP

                        Hi Jongware,

                        I think the case is a bit more complex, because Selva said:

                        … If 1st character of paragraph or last character of paragraph, no issue.

                        Some more cases to check.

                        But certainly doable.

                         

                        Regards,
                        Uwe

                        • 9. Re: Anchor mark position
                          selvam214 Level 1

                          Hi Jongware,

                          My target is achieved as per below based on your code, specially thanks for your explanation. It's very useful for feature development.

                           

                           

                          Thanks to all for the wonderful support.

                           

                           

                          var myAnchorReport=[];
                          app.findGrepPreferences = NothingEnum.NOTHING; 
                          app.findGrepPreferences.findWhat = "~a"; 
                          var objectsArray = app.activeDocument.findGrep(); 
                          for (var c = 0; c < objectsArray.length; c++){
                              if (objectsArray[c].textFrames.length > 0){
                                  var targetTextFrame = objectsArray[c].textFrames.item(0);
                                  var textFramePosition = targetTextFrame.anchoredObjectSettings.anchoredPosition;
                                  if (textFramePosition == AnchorPosition.ANCHORED){
                                      position = objectsArray[c].index - objectsArray[c].paragraphs[0].index;
                                      if (position > 0 && position < objectsArray[c].paragraphs[0].length-2)
                                      myAnchorReport.push(objectsArray[c].parentTextFrames[0].parentPage.name);
                                      }
                                  }
                              }

                           

                           

                          Selva