• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

In Design Script

Community Beginner ,
Jan 05, 2025 Jan 05, 2025

Copy link to clipboard

Copied

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

Views

71

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 06, 2025 Jan 06, 2025

Add this: 

rect.overprintStroke = true; 

After the line where you apply strokeColor. 

 

Votes

Translate

Translate
Community Beginner ,
Jan 05, 2025 Jan 05, 2025

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 06, 2025 Jan 06, 2025

Copy link to clipboard

Copied

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

 

Take a look at the overprintStroke property. 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 06, 2025 Jan 06, 2025

Copy link to clipboard

Copied

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 06, 2025 Jan 06, 2025

Copy link to clipboard

Copied

Add this: 

rect.overprintStroke = true; 

After the line where you apply strokeColor. 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 06, 2025 Jan 06, 2025

Copy link to clipboard

Copied

LATEST

LEGEND!! Thank you so so much that has instantly worked! 

Full code is as follows, in case anyone else needs it. 

#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;

// Set stroke to overprint
rect.overprintStroke = true; // Enable overprint for the stroke

// 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, "through cut" spot color, and overprint stroke enabled.');
}

// Create the rectangle with stroke using spot color and overprint stroke
createRectangleSameSizeAsPage();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 06, 2025 Jan 06, 2025

Copy link to clipboard

Copied

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">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 06, 2025 Jan 06, 2025

Copy link to clipboard

Copied

Thanks! 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines