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

# Specific scripting question - template

Hi,

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

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),

// sample code
var t = spacing + radius;
spacing+pb[0],
spacing+pb[1],
t+pb[0],
t+pb[1]
];
```

@+

Marc

• ###### 2. Re: Specific scripting question - template

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),

// sample code
var t = spacing + radius;
spacing+pb[0],
spacing+pb[1],
t+pb[0],
t+pb[1]
];
``````

@+

Marc

• ###### 3. Re: Specific scripting question - template

Hi Paul,

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),

var t = spacing + 2*radius,
c, ep;

// Create and position the circle at [top,right]
// ---
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