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

Setting specifed colours to overprint stroke, and converting to spots.

Community Beginner ,
Jan 24, 2025 Jan 24, 2025

Copy link to clipboard

Copied

Hi guys, im playing around with an idea for some automation within our print studio. We have files that have several guides such as cutters and crease guide etc.

What I am trying to do with the script is to find the named swatches, make sure that they have the overprint stroke attribute applied and then make sure that they are spots, if not then convert them.

I have managed to get the funtionality working to update the overprint attribute, but sturggling with the conversion to spot colours. The code is not throwing up any errors, so i'm a bit stumped.

Any help would be much appreciated.

// Script to set overprint stroke for objects with specific stroke colours
function main() {
    if (app.documents.length === 0) {
        alert("Please open a document before running this script.");
        return;
    }
    var doc = app.activeDocument;
    var targetColorNames = ["Visual Area (Do not Print)", "Cutter Guide", "Crease Guide"];
    var targetColors = [];
    for (var i = 0; i < targetColorNames.length; i++) {
        var color = doc.swatches.itemByName(targetColorNames[i]);
        if (color.isValid) {
            if (color.model === ColorModel.SPOT) {
                targetColors.push(color);
            } else {
                targetColors.push(convertToSpotColor(color));
            }
        }
    }
    if (targetColors.length === 0) {
        alert("None of the specified stroke colours were found in this document.");
        return;
    }
    var allPageItems = doc.allPageItems;

    for (var j = 0; j < allPageItems.length; j++) {
        var item = allPageItems[j];

        try {
            if (
                item.hasOwnProperty("strokeColor") &&
                item.strokeColor !== null &&
                item.hasOwnProperty("overprintStroke")
            ) {
                for (var k = 0; k < targetColors.length; k++) {
                    if (item.strokeColor.name === targetColors[k].name) {
                        item.overprintStroke = true;
                        break; 
                    }
                }
            }
        } catch (e) {
            $.writeln("Error processing item: " + e.message);
        }
    }

    alert("Overprint stroke attribute has been applied to all matching objects.");
}

// Function to convert a process colour to a spot
function convertToSpotColor(color) {
    try {
        var doc = app.activeDocument;
        if (color.model === ColorModel.PROCESS) {
            var spotColor = doc.spots.add();
            spotColor.name = color.name + " Spot";
            spotColor.colorType = ColorModel.SPOT;
            spotColor.color = color.color;
            var spotSwatch = doc.swatches.add();
            spotSwatch.name = spotColor.name;
            spotSwatch.color = spotColor.color;
            return spotSwatch;
        } else {
            return color;
        }
    } catch (e) {
        $.writeln("Error converting colour to Spot: " + e.message);
        return color;
    }
}

main();




TOPICS
Experiment , Print , Scripting

Views

77

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 24, 2025 Jan 24, 2025
quote

How would I convert the original?


By @Scott1992

 

The same way as when you set this property for the newly created Swatch Color:

 

spotColor.colorType = ColorModel.SPOT;

 

Just do it on the original Swatch Color.

quote

No, I dont get any errors, but not getting any new swatches.

 

Right, just checked your code again:

 

var spotColor = doc.spots.add();

 

InDesign doesn't have a "dedicated" spots collection - and you need to work on Colors collection and modify Color and set its ColorModel - not Sw

...

Votes

Translate

Translate
Community Expert ,
Jan 24, 2025 Jan 24, 2025

Copy link to clipboard

Copied

You are adding a new swatch - instead of maybe just converting original swatch?

 

Your code looks OK (I'm on my phone), so you don't get any errors in that part - but new swatches on the list?

 

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 24, 2025 Jan 24, 2025

Copy link to clipboard

Copied

How would I convert the original?
No, I dont get any errors, but not getting any new swatches.

The only thing that actually happens is the adding the overprint attribute.


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 24, 2025 Jan 24, 2025

Copy link to clipboard

Copied

quote

How would I convert the original?


By @Scott1992

 

The same way as when you set this property for the newly created Swatch Color:

 

spotColor.colorType = ColorModel.SPOT;

 

Just do it on the original Swatch Color.

quote

No, I dont get any errors, but not getting any new swatches.

 

Right, just checked your code again:

 

var spotColor = doc.spots.add();

 

InDesign doesn't have a "dedicated" spots collection - and you need to work on Colors collection and modify Color and set its ColorModel - not Swatches collection:

 

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

 

Swatches collection is kind of "meaningless" collection - just a nice list in the UI.

 

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 24, 2025 Jan 24, 2025

Copy link to clipboard

Copied

Top man Robert!

This works perfectly. thank you for your help

 

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 24, 2025 Jan 24, 2025

Copy link to clipboard

Copied

LATEST

You're welcome. 

 

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