I have very limited knowledge of scripting but am trying to create a basic script that will aid our workflow in a fast-paced production environment. What I need the overall script to do in InDesign is:
1. Create a new layer at the top of the stack called "dieline"
2. On this layer, put a rectangle the same size as the document page size and center
3. Apply a spot colour swatch called "dieline" (C0 M100 Y0 K0) to the rectangle stroke and set stroke to overprint
4. Set stroke to 1pt, apply fill to none, align stroke to center
5. Apply this rectangle to all pages of the document
By piecing together other scripts I have found online, I was able to successfully run the script below BUT encounter 2 issues:
- If a document already has a swatch called "dieline" in the swatch palette, the script errors out. I just need the script to either apply the spot colour swatch "dieline" and if the document doesnt have one, then create it.
- I cannot figure out how to set the stroke to overprint!
I am hoping someone can help me out! Here is the code:
var myDoc = app.activeDocument;
// set page origin to 0,0
myDoc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;
// get page dimensions
var myY2 = myDoc.documentPreferences.pageHeight;
var myX2 = myDoc.documentPreferences.pageWidth;
// define page count
var myPagesTotal = myDoc.pages.length;
// new layer to top of stack
var myNewLayer = myDoc.layers.add();
myNewLayer.move(LocationOptions.atBeginning, undefined);
myNewLayer.name = "dieline";
// add dieline swatch and set parameters
var spotDie = new Array(0, 100, 0, 0);
myDoc.colors.add({model:ColorModel.SPOT, space:ColorSpace.CMYK, colorValue:spotDie, name:"dieline"});
var i=0;
while ( i<myPagesTotal) { var mySpread = myDoc.pages.item(i);
var myBorder = mySpread.rectangles.add();
myBorder.geometricBounds = ["0p0", "0p0", myY2, myX2];
myBorder.strokeColor = "dieline";
myBorder.fillColor = "None";
myBorder.strokeWeight = "1pt";
myBorder.strokeAlignment = StrokeAlignment.centerAlignment;
i++;
}
MANY MANY THANKS!
(using Indesign CC)