5 Replies Latest reply on May 19, 2014 10:05 PM by Jump_Over

    Anchor required

    kanaga kumar

      Dear Friends,


      I need “Para_No” paragraph style should be placed in “archor format” in next para begining of text. This is urgent request. Kindly help in this regard.


      Actual page:

      Screen Shot 2014-05-19 at 10.25.47 AM.png


      MY Requirement:


      Screen Shot 2014-05-19 at 10.13.57 AM.png





      Thanks in advance,

      kanaga kumar. k

        • 1. Re: Anchor required
          BEGINNER_X Level 3

          Hi Kanaga,


          Before run the script, please open the document and library.


          Please create the below:


          Paragraph Styles = "Para_No"

          Library Asset Name = "ANNO"

          Object Style Name = "Object Styles"


          And also i am not tested in my end. Kindly find the code below:


          var myDoc = app.documents[0];
          var myLib = app.libraries[0];
          app.findTextPreferences = NothingEnum.nothing;
          app.changeTextPreferences = NothingEnum.nothing;
          app.findTextPreferences = null;
          app.findTextPreferences.appliedParagraphStyle= "Para_No";
          myFind = myDoc.findText(true);
          var myCount=0;
              for (var i=0; i<myFind.length; i++)  
                  var myPara = myFind[i].texts[0];  
                  myText = myLib.assets.item ("ANNO").placeAsset (myFind[i].insertionPoints[-1])[0];  
                  myPara.move(LocationOptions.AT_END, myText.insertionPoints[-1]);  
                  myText.appliedObjectStyle = myDoc.objectStyles.item ("Object Styles");  
          alert(myCount+" ANNOs are Placed Successfully...");




          • 2. Re: Anchor required
            Jump_Over Level 5



            What to do:

            • find all occurrences where thisPara is applied
            • iterate through backwards
            • add a textFrame at last insertionPoint
            • set a textFrame properties
            • move text and fit textFrame to contents
            app.findTextPreferences = null;
            app.findTextPreferences.appliedParagraphStyle = "Para_Num";
              mFound = app.activeDocument.findText(),
              len = mFound.length,
              currWidth, tarText, tarIP, currFrame, currGB,
              old_VOrigin = app.activeDocument.viewPreferences.verticalMeasurementUnits,
              old_HOrigin = app.activeDocument.viewPreferences.horizontalMeasurementUnits;
            app.activeDocument.viewPreferences.horizontalMeasurementUnits =
              app.activeDocument.viewPreferences.verticalMeasurementUnits =
            while (len-->0) {
              tarText = mFound[len];
              currWidth = tarText.lines[0].endHorizontalOffset - tarText.lines[0].horizontalOffset + 10;
              tarIP = tarText.insertionPoints[-1];
              currFrame = tarIP.textFrames.add();
              setFrame (currFrame);
              currGB = currFrame.geometricBounds;
              currGB = [currGB[0], currGB[3] - currWidth, currGB[2], currGB[3]];
              currFrame.geometricBounds = currGB;
            app.activeDocument.viewPreferences.horizontalMeasurementUnits = old_HOrigin;
            app.activeDocument.viewPreferences.verticalMeasurementUnits = old_VOrigin;
            app.findTextPreferences = null;
            function setFrame (mAnchored){
              with (mAnchored) {
              anchoredObjectSettings.anchoredPosition = AnchorPosition.ANCHORED;
              anchoredObjectSettings.anchorPoint = AnchorPoint.BOTTOM_RIGHT_ANCHOR;
              anchoredObjectSettings.horizontalReferencePoint = AnchoredRelativeTo.TEXT_FRAME;
              anchoredObjectSettings.verticalReferencePoint = VerticallyRelativeTo.LINE_BASELINE;
              textFramePreferences.insetSpacing = [0,0,0,1];
              textFramePreferences.verticalJustification = VerticalJustification.BOTTOM_ALIGN;



            • 3. Re: Anchor required
              kanaga kumar Level 1

              Dear Siraj,

              Thanks for your timely help, and its working fine. Also i need two kind of clarifications based on above mentioned requirement:

              1. Multiple styles how to used same method

              2. Common arts need to place in same method


              Kindly advice and it is possible?



              kanaga kumar. k

              • 4. Re: Anchor required
                hasvi Level 1



                I try to run this script, but my Indesign file is closed when I run this script, can you help me?




                • 5. Re: Anchor required
                  Jump_Over Level 5



                  How big is mFound.length on your side?

                  Is "live pages" feature active in your doc?

                  Did you try to debug a code by running it from ESTK with breakpoints inserted?


                  Try to run findText() with smaller target than app.activeDocument

                  For example: app.activeDocument.stories[0].paragraphs.itemByRange(0,50).texts[0];




                  PS Last thing I thought about: Be sure to run this code with "Para_Num" style applied to plain textFrame contents. I mean do not run it if some part are moved into anchored textFrames already.