5 Replies Latest reply on Oct 21, 2015 8:03 AM by Jump_Over

    FIND OBJECT OUTSIDE SAFETY MARGIN

    tpk1982 Level 4

      Hello Friends,

       

      I need your help to solve my 3 days headache. Really worried why it is not working.

       

      Screen Shot 2015-10-21 at 10.53.25 AM.png

       

      I have 12" page with fold lines of 4" and 8" (can be seen in slug area in above image). So we need to check whether any page element should not cross the 4" and 8" fold lines. Instead of guides (as shown in above picture), i created script with UI, getting 2 fold values, created graphic line and checking the overlap items. With this we can know the page elements which cross 4" or 8" or not. This is what my logic.

       

      The below are the tried codes:

       

      var doc = app.activeDocument;   

      doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.INCHES;

      doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.INCHES;

      var myDialog = app.dialogs.add({name:"FIND OBJECT OUTSIDE SAFETY MARGIN",canCancel:true});

      with(myDialog){

        with(dialogColumns.add()){

                      with(borderPanels.add()){

          staticTexts.add({staticLabel:"Please Enter First Final Folded Width:               "});

        var myFirstFold = realEditboxes.add();

                         

                          }

                      with(borderPanels.add()){

          staticTexts.add({staticLabel:"Please Enter Second Final Folded Width:           "});

        var mySecondFold = realEditboxes.add();

                         

                          }

                      with(borderPanels.add()){

          staticTexts.add({staticLabel:"Please Enter Third Final Folded Width (if any):  "});

        var myThirdFold = realEditboxes.add();

                          }

      }

      }

      var myResult = myDialog.show();

      if(myResult == true){

          myFirstFoldValue = myFirstFold.editValue;

          mySecondFoldValue = mySecondFold.editValue;

          myThirdFoldValue = myThirdFold.editValue;

       

      //w = doc.documentPreferences.pageWidth,   

      h = doc.documentPreferences.pageHeight;   

      if(myFirstFoldValue!=null)

      {

      var myOutsideGuide_Left = app.activeWindow.activePage.graphicLines.add ({strokeWeight: 0.5});

      myOutsideGuide_Left.geometricBounds = ["0 in", myFirstFoldValue, h, myFirstFoldValue];

      }

      if(mySecondFoldValue!=null)

      {

      var myOutsideGuide1_Left = app.activeWindow.activePage.graphicLines.add ({strokeWeight: 0.5});

      myOutsideGuide1_Left.geometricBounds = ["0 in", mySecondFoldValue, h, mySecondFoldValue];

      }

      if(myThirdFoldValue!=null)

      {

          var myOutsideGuide2_Left = app.activeWindow.activePage.graphicLines.add ({strokeWeight: 0.5});

      myOutsideGuide2_Left.geometricBounds = ["0 in", myThirdFoldValue, h, myThirdFoldValue];

      }

      }

      myoverlap();

      myoverlapgraphic();

      myoverlaprec();

      //app.activeWindow.activePage.graphicLines.everyItem().remove ({strokeWeight: 0.5});

       

      function myoverlap()

      {

      var overlapArray = new Array();

          var mygraphicLines = app.activeWindow.activePage.graphicLines;

          var myPgItems = app.activeWindow.activePage.textFrames;

             var kk=app.activeWindow.activePage.name

       

          for(k=0;k<myPgItems.length;k++)

              {

                  var bounds1 = myPgItems[k].geometricBounds;

       

                  for(j=0;j<mygraphicLines.length;j++)

      {

                      var bounds2 = mygraphicLines[j].geometricBounds;

                      if(myPgItems[k] ==  mygraphicLines[j])

                          {

                              continue;

                              }

                          var temp = touches(bounds1,bounds2);

       

       

                          if(temp == true)

                          {

                              alert("Found overlapped Textframes" + " in Page: " + kk);

                          }

                  }

              }

      }

       

       

      function myoverlapgraphic()

      {

      var overlapArray = new Array();

          var mygraphicLines = app.activeWindow.activePage.graphicLines;

          var myPgItems = app.activeWindow.activePage.allGraphics;

      var k=app.activeWindow.activePage.name

          for(k=0;k<myPgItems.length;k++)

              {

                  var bounds1 = myPgItems[k].geometricBounds;

       

       

                  for(j=0;j<mygraphicLines.length;j++)

                  {

                      var bounds2 = mygraphicLines[j].geometricBounds;

                      if(myPgItems[k] ==  mygraphicLines[j])

                          {

                              continue;

                              }

                          var temp1 = touches(bounds1,bounds2);

       

       

                          if(temp1 == true)

                          {

                              alert("Found overlapped Graphicframes" + " in Page: " + k);

                          }

                  }

              }

      }

       

      function myoverlaprec()

      {

      var overlapArray = new Array();

          var mygraphicLines = app.activeWindow.activePage.graphicLines;

          var myPgItems = app.activeWindow.activePage.rectangles;

      var k=app.activeWindow.activePage.name

          for(k=0;k<myPgItems.length;k++)

              {

                  var bounds1 = myPgItems[k].geometricBounds;

       

       

                  for(j=0;j<mygraphicLines.length;j++)

                  {

                      var bounds2 = mygraphicLines[j].geometricBounds;

                      if(myPgItems[k] ==  mygraphicLines[j])

                          {

                              continue;

                              }

                          var temp2 = touches(bounds1,bounds2);

       

       

                          if(temp2 == true)

                          {

                              alert("Found overlapped rectangles" + " in Page: " + k);

                          }

                  }

              }

      }

       

       

      function touches(bounds1,bounds2)

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

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

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

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

          return true;

          }

       

      Hope it is clear.

       

      But it shows the overlap alert even it is not overlapping. Also it created a line in 0" left side unnecessarily.

       

      Advance thanks.

       

      Karthi

        • 1. Re: FIND OBJECT OUTSIDE SAFETY MARGIN
          BEGINNER_X Level 3

          Hi Karthi,

           

          May the below code is useful for you...

           

          Change the value in the 15th line.

           

          app.activeDocument.viewPreferences.horizontalMeasurementUnits =  MeasurementUnits.MILLIMETERS;
          app.activeDocument.viewPreferences.verticalMeasurementUnits =  MeasurementUnits.MILLIMETERS;
          app.activeDocument.zeroPoint = [0,0]; 
          
          var myPgItems = app.activeDocument.allPageItems;
          
          var myPageHeight = app.activeDocument.documentPreferences.pageHeight;
          
          myPageWidth = app.activeDocument.documentPreferences.pageWidth;
          
          try{
          for(k=0; k<myPgItems.length; k++)
          {
              myGMB = myPgItems[k].geometricBounds;
              if(myGMB[0]==0 || myGMB[1]==0 || myGMB[2]==myPageHeight  || myGMB[3]==myPageWidth)  //Change the value as per your requirment
              {
               app.select(myPgItems[0])
               
              }
          }
          }
          catch(e){}
          
          • 2. Re: FIND OBJECT OUTSIDE SAFETY MARGIN
            tpk1982 Level 4

            Hi Siraj,

             

            Thank for your valuable input. But my actual requirement is i need to check the overlap of graphicline with pageitems.

             

            My code showing wrong alerts even it is not overlapped. That need to be rectified.

             

            Regards

            Karthi

            • 3. Re: FIND OBJECT OUTSIDE SAFETY MARGIN
              Jump_Over Level 5

              Hi,

               

              In this particular case - assuming we are comparing vertical graphic lines which are higher than page -

              function touches supposes to return true if:

              checkedObject.geometricBounds[1] < vertLine.geometricBounds[1] && vertLine.geometricBounds[1] < checkedObject.geometricBounds[3]

               

              so rebuild this function like

              function touches (mBounds, mLines)
              {
              for (var k = 0; k < mLines.length; k ++)
                  if (mBounds[3] > mLines[k].geometricBounds[1] && mBounds[1] < mLines[k].geometricBounds[1] )
                        return true;
              return false
              }
              
              

               

              mLines is an array with graphicLines

              mBounds are geometricBounds to check.

               

              Jarek

              • 4. Re: FIND OBJECT OUTSIDE SAFETY MARGIN
                tpk1982 Level 4

                Hi Jarek,

                 

                Thanks for your time and reply. I am not comparing graphic line height with pageitems height. Instead of height, i need to check the page item should not go over the graphic lines. (say width wise)

                 

                For example, i place a graphic line on 4" in the document. I need to check the page item which are crossing 4". Likewise i need to check 2 or more folds depend on user input.

                 

                Hope i explained little more now.

                 

                Regards,

                Karthi

                • 5. Re: FIND OBJECT OUTSIDE SAFETY MARGIN
                  Jump_Over Level 5

                  Hi,

                   

                  Explained good enough already.

                  Hope you will test my solution.

                   

                  Jarek