8 Replies Latest reply on Jan 6, 2017 4:00 AM by keyank99503373

    Avoid overlap anchor object

    keyank99503373

      we'd like to fix a validation in Script to identify the anchored objects which are overlapping while running the script, The below code is working for most of the cases but if i have more than five query in a para its not working. could anyone advise on this?

       

      var myDoc = app.activeDocument;

      myDoc.preflightOptions.preflightOff = true;

      myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;

      myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;

      myDoc.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;

      myDoc.zeroPoint = [0,0];

      var myAllNotesArray = myDoc.stories.everyItem().notes.everyItem().getElements(), myNotesBasealign , myPage, myNotes , myNotetextframe = []; 

      var pageLeft = myDoc.pages[0].marginPreferences.right - 9;

      var pageRight = myDoc.pages[0].marginPreferences.left - 9;

       

       

      try{if (myDoc.paragraphStyles.item('AuthorQueries') == null) { var AuthorQueries = myDoc .paragraphStyles.add({name:'AuthorQueries', appliedFont:"Times LT Std", pointSize:6, leading:7});}} catch (e){    }

       

       

       

       

          authorQueryPlacement()

          checkstackOrder()

          spineRelative()

          avoidOversetspineRelative()

       

       

          function checkstackOrder()

          {

              if (myNotetextframe != null)

              {

                  for (var i =0;i<myNotetextframe.length;i++)

                  {

                     for (var j =i+1;j<myNotetextframe.length;j++)

                          {         

                              if (touches(myNotetextframe[i], myNotetextframe[j]) ==  true)

                              {

                              myNotetextframe[j].anchoredObjectSettings.spineRelative=false;

                              }

                          }            

                      }

              }

             

           } // fn close

       

       

          function spineRelative()

          {

              if (myNotetextframe != null)

              {

                  for (var i =0;i<myNotetextframe.length;i++)

                  {            

                      if (myNotetextframe[i].anchoredObjectSettings.spineRelative==false)

                      {

                          for (var j =i+1;j<myNotetextframe.length;j++)

                          {

                              if (touches(myNotetextframe[i], myNotetextframe[j]) ==  true)

                              {          

                                      if (myNotetextframe[i].geometricBounds[2]  > myNotetextframe[j].geometricBounds[0]  )

                                      {

                                              var diff = myNotetextframe[i].geometricBounds[2] - myNotetextframe[j].geometricBounds[0]                                        

                                              mydiff = (myNotetextframe[j].anchoredObjectSettings.anchorYoffset) + ( diff +12)

                                              myNotetextframe[j].anchoredObjectSettings.anchorYoffset = mydiff;

                                       }

                                      break;

                               }                           

                           }  

                       }

                   }

              }

           } // fn close

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

      function touches(bounds1, bounds2) 

      if (bounds1.geometricBounds[2] < bounds2.geometricBounds[0]) return false; 

      if (bounds1.geometricBounds[0] > bounds2.geometricBounds[2]) return false; 

      if (bounds1.geometricBounds[1] > bounds2.geometricBounds[3]) return false; 

      if (bounds1.geometricBounds[3] < bounds2.geometricBounds[1]) return false; 

        return true; 

      }  

       

       

       

       

       

       

      function authorQueryPlacement()

      {

          for(i=0; i<myAllNotesArray.length;i++)

          { 

           if (myAllNotesArray[i].texts[0] != '' )

           {

                 myPage = myAllNotesArray[i].storyOffset.insertionPoints[0].parentTextFrames[0].parentPage.name;

                 myNotes = myAllNotesArray[i].storyOffset.insertionPoints[0].textFrames.add({geometricBounds:[0,0,pa geLeft,pageLeft]});  

                 myNotes.anchoredObjectSettings.anchoredPosition=AnchorPosition.anchored;

                 myNotes.anchoredObjectSettings.horizontalReferencePoint = AnchoredRelativeTo.TEXT_FRAME;

                 myNotes.anchoredObjectSettings.verticalReferencePoint = VerticallyRelativeTo.capheight;

                 myNotes.anchoredObjectSettings.anchorXoffset=+5.5

                  myAllNotesArray[i].texts[0].duplicate(LocationOptions.AFTER,myNotes.parentStory.texts[0]. insertionPoints[0]); 

                 myNotes.paragraphs[0].applyParagraphStyle(myDoc.paragraphStyles.itemByName("AuthorQueries "));

                 myNotes.textFramePreferences.autoSizingReferencePoint = AutoSizingReferenceEnum.TOP_CENTER_POINT;

                 myNotes.textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_ONLY;

                 myNotes.anchoredObjectSettings.spineRelative=true;

                 delEndEnterMark(myNotes)

                 myNotes.textFramePreferences.autoSizingType = AutoSizingTypeEnum.OFF;

                 myNotes.fit(FitOptions.FRAME_TO_CONTENT);   

                 app.select(myNotes)

                 frameHeight  = app.selection[0].geometricBounds[2] -  app.selection[0].geometricBounds[0]

                 myNotes.anchoredObjectSettings.anchorYoffset=+ frameHeight;

                 myNotetextframe.push(myNotes);

              }

          }

      }

        • 1. Re: Avoid overlap anchor object
          keyank99503373 Level 1

          Any idea or logic to clear the anchor overlap?

          • 2. Re: Avoid overlap anchor object
            Obi-wan Kenobi Adobe Community Professional

            Hi,

             

            Can you send us a test file?

             

            (^/)

            • 3. Re: Avoid overlap anchor object
              keyank99503373 Level 1

              Herewith i have attached file for your reference.

               

              On Wed, Jan 4, 2017 at 6:11 PM, Obi-wan Kenobi <forums_noreply@adobe.com>

              • 5. Re: Avoid overlap anchor object
                Obi-wan Kenobi Adobe Community Professional

                Where?

                 

                Make a dropbox or wetransfer file!

                 

                (^/)

                • 6. Re: Avoid overlap anchor object
                  Trevorׅ Adobe Community Professional

                  Hi Kenyank

                   

                  1) When you post code please use the advanced editor (link on the top right of the reply box) so you can format your code and have is semi-readable.

                  To format it click on the >> next to the    Syntax Highlighting > Java or JavasScript

                  2) A screenshot or 2 can be very usefull

                   

                  If you can send a link by https://wetransfer.com/ it would be good but it look's like they've got an outage right now.

                   

                  Below is Your code formatted.

                   

                  Sadly formatting it will not make it work so it still won't work but at least it will be a bit more inviting for people to look at.

                   

                  var myDoc = app.activeDocument;
                  myDoc.preflightOptions.preflightOff = true;
                  myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;
                  myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;
                  myDoc.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;
                  myDoc.zeroPoint = [0, 0];
                  var myAllNotesArray = myDoc.stories.everyItem().notes.everyItem().getElements(),
                      myNotesBasealign, myPage, myNotes, myNotetextframe = [];
                  var pageLeft = myDoc.pages[0].marginPreferences.right - 9;
                  var pageRight = myDoc.pages[0].marginPreferences.left - 9;
                  try {
                      if (myDoc.paragraphStyles.item('AuthorQueries') == null) {
                          var AuthorQueries = myDoc.paragraphStyles.add({
                              name: 'AuthorQueries',
                              appliedFont: "Times LT Std",
                              pointSize: 6,
                              leading: 7
                          });
                      }
                  } catch (e) {}
                  authorQueryPlacement()
                  checkstackOrder()
                  spineRelative()
                  avoidOversetspineRelative()
                  
                  function checkstackOrder() {
                      if (myNotetextframe != null) {
                          for (var i = 0; i < myNotetextframe.length; i++) {
                              for (var j = i + 1; j < myNotetextframe.length; j++) {
                                  if (touches(myNotetextframe[i], myNotetextframe[j]) == true) {
                                      myNotetextframe[j].anchoredObjectSettings.spineRelative = false;
                                  }
                              }
                          }
                      }
                  
                  } // fn close
                  function spineRelative() {
                      if (myNotetextframe != null) {
                          for (var i = 0; i < myNotetextframe.length; i++) {
                              if (myNotetextframe[i].anchoredObjectSettings.spineRelative == false) {
                                  for (var j = i + 1; j < myNotetextframe.length; j++) {
                                      if (touches(myNotetextframe[i], myNotetextframe[j]) == true) {
                                          if (myNotetextframe[i].geometricBounds[2] > myNotetextframe[j].geometricBounds[0]) {
                                              var diff = myNotetextframe[i].geometricBounds[2] - myNotetextframe[j].geometricBounds[0]
                                              mydiff = (myNotetextframe[j].anchoredObjectSettings.anchorYoffset) + (diff + 12)
                                              myNotetextframe[j].anchoredObjectSettings.anchorYoffset = mydiff;
                                          }
                                          break;
                                      }
                                  }
                              }
                          }
                      }
                  } // fn close
                  function touches(bounds1, bounds2) {
                      if (bounds1.geometricBounds[2] < bounds2.geometricBounds[0]) return false;
                      if (bounds1.geometricBounds[0] > bounds2.geometricBounds[2]) return false;
                      if (bounds1.geometricBounds[1] > bounds2.geometricBounds[3]) return false;
                      if (bounds1.geometricBounds[3] < bounds2.geometricBounds[1]) return false;
                      return true;
                  }
                  
                  function authorQueryPlacement() {
                      for (i = 0; i < myAllNotesArray.length; i++) {
                          if (myAllNotesArray[i].texts[0] != '') {
                              myPage = myAllNotesArray[i].storyOffset.insertionPoints[0].parentTextFrames[0].parentPage.name;
                              myNotes = myAllNotesArray[i].storyOffset.insertionPoints[0].textFrames.add({
                                  geometricBounds: [0, 0, pageLeft, pageLeft]
                              });
                              myNotes.anchoredObjectSettings.anchoredPosition = AnchorPosition.anchored;
                              myNotes.anchoredObjectSettings.horizontalReferencePoint = AnchoredRelativeTo.TEXT_FRAME;
                              myNotes.anchoredObjectSettings.verticalReferencePoint = VerticallyRelativeTo.capheight;
                              myNotes.anchoredObjectSettings.anchorXoffset = +5.5
                              myAllNotesArray[i].texts[0].duplicate(LocationOptions.AFTER, myNotes.parentStory.texts[0].insertionPoints[0]);
                              myNotes.paragraphs[0].applyParagraphStyle(myDoc.paragraphStyles.itemByName("AuthorQueries "));
                              myNotes.textFramePreferences.autoSizingReferencePoint = AutoSizingReferenceEnum.TOP_CENTER_POINT;
                              myNotes.textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_ONLY;
                              myNotes.anchoredObjectSettings.spineRelative = true;
                              delEndEnterMark(myNotes)
                              myNotes.textFramePreferences.autoSizingType = AutoSizingTypeEnum.OFF;
                              myNotes.fit(FitOptions.FRAME_TO_CONTENT);
                              app.select(myNotes)
                              frameHeight = app.selection[0].geometricBounds[2] - app.selection[0].geometricBounds[0]
                              myNotes.anchoredObjectSettings.anchorYoffset = +frameHeight;
                              myNotetextframe.push(myNotes);
                          }
                      }
                  }
                  

                   

                  1 person found this helpful
                  • 8. Re: Avoid overlap anchor object
                    keyank99503373 Level 1

                    Any suggestion