3 Replies Latest reply on Mar 1, 2011 1:46 AM by Marc Autret

    Specific scripting question - template

    Paul Hurd

      Hi,

       

      I'm hoping to get some advice or a template to start with for this challenge.

       

      My company's brand guidelines have a specific formula for creating a particular piece of art on a printed document that goes like this: Draw a line, diagonally from one corner to the other. Take the length of that line and divide by 12. This is the radius of the curve for this piece of art. Take that same radius and divide again by 3 to calculate the spacing of this piece of art from the left edge of the page.

       

      I'm able to do this pretty easily in Indesign and Illustrator by using the calculations feature in the measurements boxes but I was wondering if there wasn't a macro/script that would accomplish the same thing with a click of a button. I suppose I could make templates for this, based on standard paper sizes, but I deal a lot with large graphics for tradeshows and they're not always the same size. A script would be great.

       

      Thanks,

      Paul

        • 1. Re: Specific scripting question - template
          Marc Autret Level 4

          Hi Paul,

           

          The Pythagorean theorem is your friend:

           

          var pg = app.activeWindow.activePage,
               pb = pg.bounds,
               w = pb[3]-pb[1],
               h = pb[2]-pb[0],
               diag = Math.sqrt(w*w+h*h),
               radius = diag/12.0, // your radius
               spacing = radius/3.0; // your spacing
          
          // sample code
          var t = spacing + radius;
          pg.ovals.add().geometricBounds = [
               spacing+pb[0],
               spacing+pb[1],
               t+pb[0],
               t+pb[1]
               ];
          

           

          @+

          Marc

          1 person found this helpful
          • 2. Re: Specific scripting question - template
            Paul Hurd Level 1

            Marc,

             

            Awesome. Of course, the radius must be doubled in order to draw the correct circle diameter.

             

            What I'm unable to figure out is how to set the circle to the right side of the page, set off by that magical radius/3.0 measure from the right edge of the page.

             

            Also, is there a way to then cut the anchors from the top and right, delete the rest of the circle and extend the line to the bottom and left as if it were the corner of a rounded rectangle? Would it be better achieved by approaching the pg.ovals.add().geometricBounds a different way?  Not being very comfortable with Java makes it difficult to see the possibilities.

             

            It would be easier, I would think, if I didn't have to do this, manually, many times over the course of a day but, like I said before, I deal with varying page sizes and it all has to work.

             

            Thanks,

            Paul

             

            Marc Autret wrote:

             

            Hi Paul,

             

            The Pythagorean theorem is your friend:

             

            var pg = app.activeWindow.activePage,
                 pb = pg.bounds,
                 w = pb[3]-pb[1],
                 h = pb[2]-pb[0],
                 diag = Math.sqrt(w*w+h*h),
                 radius = diag/12.0, // your radius
                 spacing = radius/3.0; // your spacing
             
            // sample code
            var t = spacing + radius;
            pg.ovals.add().geometricBounds = [
                 spacing+pb[0],
                 spacing+pb[1],
                 t+pb[0],
                 t+pb[1]
                 ];
            

             

            @+

            Marc

            • 3. Re: Specific scripting question - template
              Marc Autret Level 4

              Hi Paul,

               

              Damn, you're hard to please

               

              Try this:

               

              var pg = app.activeWindow.activePage,
                   pb = pg.bounds,
                   w = pb[3]-pb[1],
                   h = pb[2]-pb[0],
                   diag = Math.sqrt(w*w+h*h),
                   radius = diag/12.0, // your radius
                   spacing = radius/3.0; // your spacing
               
              var t = spacing + 2*radius,
                   c, ep;
              
              // Create and position the circle at [top,right]
              // ---
              (c=pg.ovals.add()).geometricBounds = [
                   pb[0]+spacing,
                   pb[3]-t,
                   pb[0]+t,
                   pb[3]-spacing
                   ];
              
              // Reduce the path points to a top-right corner
              // ---
              ep = c.paths[0].entirePath;
              ep[0] = [ep[1][1][0], ep[0][1][1]];
              ep[1][0] = ep[1][1].concat();
              ep[3] = [ep[3][1][0], ep[2][1][1]];
              ep[2][2] = ep[2][1].concat();
              c.paths[0].properties = {
                   entirePath: ep,
                   pathType: PathType.OPEN_PATH
                   };
              

               

              @+

              Marc