Skip to main content
Known Participant
January 6, 2025
Answered

In Design Script

  • January 6, 2025
  • 3 replies
  • 406 views

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();

    Correct answer Robert at ID-Tasker

    Add this: 

    rect.overprintStroke = true; 

    After the line where you apply strokeColor. 

     

    3 replies

    kglad
    Community Expert
    Community Expert
    January 6, 2025

    in the future, to find the best place to post your message, use the list here, https://community.adobe.com/

    p.s. i don't think the adobe website, and forums in particular, are easy to navigate, so don't spend a lot of time searching that forum list. do your best and we'll move the post (like this one has already been moved) if it helps you get responses.



    <"moved from using the community">
    Ally C 25Author
    Known Participant
    January 6, 2025

    Thanks! 

    Robert at ID-Tasker
    Legend
    January 6, 2025

    https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Rectangle.html

     

    Take a look at the overprintStroke property. 

     

    Ally C 25Author
    Known Participant
    January 6, 2025

    Thank you! I have tried boolean and instructing chat GPT to use methods like this. Unfortunately I'm not one for coding so I am relying on chat GPT to do this for me and it just seems we are going in circles and eventually get to the point that it tells me its a manual function that cannot be automated. 

    Robert at ID-Tasker
    Robert at ID-TaskerCorrect answer
    Legend
    January 6, 2025

    Add this: 

    rect.overprintStroke = true; 

    After the line where you apply strokeColor. 

     

    Ally C 25Author
    Known Participant
    January 6, 2025

    If it helps, these are the steps i gave Chat GPT to create this above script. - whenever i try adn add the overprint command/function, it just doesnt work. 

    i need a script that completes the following steps, in this order.
    1. Create a layer called "cut" if one does not already exist.
    2. Create a frame to the page size.
    3. Put frame on "cut" layer - create if doesnt exist.
    4. set stroke to 0.25pt.
    5. Create spot colour "through cut"
    6. Assign "through cut" to frame stroke