2 Replies Latest reply on Jul 3, 2012 10:53 AM by alexthebake

    Script that adds objects every 2ft.

    alexthebake

      Hi,

       

      So I need to make a script that adds an object every 2 feet around the perimeter of the page.

      I really just have no idea how to start. If anyone could point me in the right direction, or show me an example of something similar being done, that would be awesome!

      This is what I have so far:

       

       

      if (x2 >= 96 || y2 >= 96) { /* If x or y are longer than 8 Feet (96 inches) */    
          var x = x2/24;
          while (x > 36 && x < 24) { /* Objects need to be added every 2 to 3 feet */
              x /= 24;
          }
      
          var y = y2/24;
          while (y > 36 && y < 24) { /* Objects need to be added every 2 to 3 feet */
              y /= 24;
          }
      }
      

       

      What I've been thinking (and what I have) is to get some fixed amount between 2 to 3 feet. Then I divide the total x or total y by that fixed amount, and that tells me how many objects I'll need to add.

      I feel like I'm heading on the right track, but making the elements seems to be the most challenging part. I have a function that makes the element I need, and the function is formatted like this: addCircle(page, top, left, bottom, right);

       

      Any help would be greatly appreciated! Thanks.

       

      EDIT:

       

      I have come up with a solution! (somewhat)

      So far it only does one side, but this works:

       

       

      var x = x2/24;
      while (x > 36 && x < 24) {
          x /= 24;
      }
      x = Math.round(x);
      var stride = (x2/x);
              
      for (var i = 0; i <= x; i++) {
          if (i == 0) {
              addCircle (myPage, 0.25, stride*i + 0.25, 0.5, stride*i + 0.5);
          } else if (i == x) {
              addCircle (myPage, 0.25, stride*i - 0.25, 0.5, stride*i);
          } else {
              addCircle (myPage, 0.25, stride*i, 0.5, stride*i + 0.25);
          }
      }