4 Replies Latest reply on Jun 23, 2013 9:49 PM by Ben_Lindsey

    Centerlines on All Artboards

    Ben_Lindsey Level 1

      Hello Everyone,

       

      I'm trying to create some simple vertical centerlines to be drawn in the same spot on all existing artboards in my document.  What I have so far is creating the proper amount of centerlines but only drawing them in the correct spot on half of the artboards while the other half are being drawn in the space between the artboards.  Here's what I have so far.

       

       

      function addCenterLines() {
          var doc = app.activeDocument;
      
          for (var i = 0; i < doc.artboards.length; i++) {
      
          var abRect = doc.artboards[i].artboardRect;
      
      
          { // Add top line
          var line = doc.pathItems.add();
          line.stroked = true;
          line.setEntirePath( Array( Array(abRect[2]/2, abRect[1]-10), Array(abRect[2]/2, abRect[1]-20) ) );
          };
      
      
          { // Add bottom line
          var line = doc.pathItems.add();
          line.stroked = true;
          line.setEntirePath( Array( Array(abRect[2]/2, abRect[3]+10), Array(abRect[2]/2, abRect[3]+20) ) );
          };
      
      
          }
      }
      
      

       

      Here's a screenshot showing the top of a couple of the artboards and the misplaced centerlines in between.

       

      abTop.jpg

       

      I think I have a great misunderstanding of how the abRect coordinates work, as in which side is [0],[1],[2] and [3], which may be leading to my inability to get this right.  If someone could point me in the right direction so I can sort out my centerlines, I would be greatly appreciative!

       

      Thank you,

      Ben

       

      NOTE: The centerlines provided in the print dialog are not an option in this case.

        • 1. Re: Centerlines on All Artboards
          CarlosCanto Adobe Community Professional & MVP

          artboarRect array values are [left, top, right, bottom]

           

          check this sample, I got carried away and added Horizontal lines

           

          function addCenterLines() {
              var doc = app.activeDocument;
              for (var i = 0; i < doc.artboards.length; i++) {
          
              var abRect = doc.artboards[i].artboardRect;
          
              // be more explicit to make it easier to visualize/read/handle
              var abLeft = abRect[0];
              var abTop = abRect[1];
              var abRight = abRect[2];
              var abBottom = abRect[3];
          
              var abWidth = abRect[2]-abRect[0];
              var abHeight = abRect[1]-abRect[3];
              var abCenter = abWidth/2;
              var abMiddle = abHeight/2;
          
          
              { // Add top line
              var line = doc.pathItems.add();
              line.stroked = true;
              line.setEntirePath( Array( Array(abLeft+abCenter, abTop-10), Array(abLeft+abCenter, abTop-20) ) );
              };
          
          
              { // Add bottom line
              var line = doc.pathItems.add();
              line.stroked = true;
              line.setEntirePath( Array( Array(abLeft+abCenter, abBottom+10), Array(abLeft+abCenter, abBottom+20) ) );
              };
          
          
              { // Add left line
              var line = doc.pathItems.add();
              line.stroked = true;
              line.setEntirePath( Array( Array(abLeft+10, abBottom+abMiddle), Array(abLeft+20, abBottom+abMiddle) ) );
              };
          
          
              { // Add right line
              var line = doc.pathItems.add();
              line.stroked = true;
              line.setEntirePath( Array( Array(abRight-10, abBottom+abMiddle), Array(abRight-20, abBottom+abMiddle) ) );
              };
          
          
              }
          }
          
          
          addCenterLines ();
          
          • 2. Re: Centerlines on All Artboards
            Muppet Mark Level 5

            Is this needed… artboards have both center mark and cross hairs… both of which are scriptable options…

            1 person found this helpful
            • 3. Re: Centerlines on All Artboards
              Ben_Lindsey Level 1

              Wow!  Thank you, Carlos!  Not only does this solve my dilemma, this definitely helps me sort out what's going on with the artboardRect for my future projects as well.

               

              Thank you so very much!

              • 4. Re: Centerlines on All Artboards
                Ben_Lindsey Level 1

                Thank you, Mark.  I didn't know that but I'll look into it for my next go.  After all of the searching I did here, I couldn't find anything referencing this.  That's probably because I was on the kick of having to solve this via the artboardRect.  I didn't even bother searching for "centerlines" in the scripting reference guide.

                 

                Thanks again, Mark.  Very helpful, as always!