In Design Script
Hi All,
I have the following script for PC. Its working perfectly, except I need to set the "through cut" spot colour to overprint, and no matter what we (myself & Chat GPT) try, it just will not do it. I know this is possible as I have had it at a previous workplace, but I didn't create that script and so did not take it with me when I left.
Any assistance is appreciated!
#target indesign
// Function to create or get the "Cut" layer
function createOrGetCutLayer() {
var doc = app.activeDocument; // Get the active document
var cutLayer = doc.layers.itemByName("cut");
// If the layer doesn't exist, create it
if (!cutLayer.isValid) {
cutLayer = doc.layers.add({ name: "cut" });
alert('Layer "cut" has been created.');
} else {
alert('Layer "cut" already exists.');
}
return cutLayer;
}
// Function to create or get the "Through Cut" spot color
function getOrCreateThroughCutSpotColor() {
var doc = app.activeDocument;
var spotColor;
// Check if the spot color "Through Cut" already exists in the swatches
try {
spotColor = doc.colors.itemByName("through cut");
// If the swatch is invalid, throw an error to create it
if (!spotColor.isValid) {
throw new Error("Spot color not found");
}
alert('Spot color "through cut" found and used.');
} catch (e) {
// If the swatch doesn't exist, create it as a global spot color
var spotColorDefinition = doc.colors.add();
spotColorDefinition.name = "through cut"; // Name the spot color
spotColorDefinition.model = ColorModel.SPOT; // Set it as a spot color
spotColorDefinition.space = ColorSpace.CMYK;
spotColorDefinition.colorValue = [0, 100, 0, 0]; // CMYK 100% Magenta
alert('Spot color "through cut" created with 100% Magenta.');
spotColor = spotColorDefinition;
}
return spotColor;
}
// Function to create a rectangle the same size as the page with a spot color stroke
function createRectangleSameSizeAsPage() {
var doc = app.activeDocument; // Get the active document
var page = doc.pages[0]; // Get the first page (adjust if needed for multiple pages)
// Get the page dimensions
var pageWidth = doc.documentPreferences.pageWidth;
var pageHeight = doc.documentPreferences.pageHeight;
// Create the rectangle with the same size as the page
var rect = page.rectangles.add({
geometricBounds: [0, 0, pageHeight, pageWidth] // [top, left, bottom, right]
});
// Apply 0.25 pt stroke weight
rect.strokeWeight = 0.25;
// Get or create the "Through Cut" spot color
var spotColor = getOrCreateThroughCutSpotColor();
// Apply the spot color to the rectangle's stroke
rect.strokeColor = spotColor;
// Remove the fill color (optional)
rect.fillColor = doc.swatches.itemByName('None'); // No fill
// Get or create the "cut" layer
var cutLayer = createOrGetCutLayer();
// Place the rectangle on the "cut" layer
rect.itemLayer = cutLayer;
alert('Rectangle created on "cut" layer with the same size as the page, 0.25 pt stroke, and "through cut" spot color.');
}
// Create the rectangle with stroke using spot color
createRectangleSameSizeAsPage();
