Tuesday, October 10, 2006

 

Avoiding Math

Faced with the task of making sure that a rectangle was trimmed so it fit on its page (that is, I needed to crop any part of it that bled off the page), my first thought was to start messing around with comparing geometric bounds, but then it hit me that the Pathfinder functions are available to a script, so what if I create a rectangle that is exactly the same size as the page and then use Intersect?

Sounds good. In the UI, the resultant page item takes on the characteristics of the front item of the two (or more, I suppose, but I'm only work with two items), so my first thought was to create the rectangle and send it to the back, like this:
myPage = app.selection[0].parent;
myNewRect = myPage.textFrames.add({geometricBounds:myPage.bounds});
myNewRect.sendToBack();
myNewShape = app.selection[0].intersectPath(myNewRect)
Hey! I hear you say, that's not a rectangle, it's a text frame you created. Well that's to end-run the issues of stroke weights. A frame is rectangular and after using intersectPath, the new shape will have the characteristics of the front item, so it doesn't matter.

Except that this doesn't work. The UI's front/back rule doesn't apply in scripts. What matters is which object has the method applied to it. So, the script I was really looking for was this:
myPage = app.selection[0].parent;
myNewRect = myPage.textFrames.add({geometricBounds:myPage.bounds});
myNewShape = myNewRect.intersectPath(app.selection[0])
No need to send to back; just apply the method to the new frame and the result takes on the characteristics (including the script label, I'm pleased to say) of the argument object.

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?