Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


performBlackOverprint() function not working

Advocate ,
Nov 22, 2021 Nov 22, 2021

Copy link to clipboard

Copied

Hello,

I want to add a function to set pure black to overprint as part of an automated process.

I've been trying to get the below function to work from the post below, but I just can't figure out why it doesn't seem to do anything....any ideas or suggestions??

https://gist.github.com/swasher/7eaa101abccf7b74409b

#target Illustrator

function performBlackOverprint()
{

var doc = app.activeDocument; 

    // var doc = sourceDoc;
    // var k;

    if(doc.documentColorSpace == DocumentColorSpace.RGB) {
        alert("The working color space is RGB. Change the document color mode to CMYK.",
            "CMYK working space required!");
        }

    else {

        // Skip Blank text frames
        for ( k = 0 ; k < doc.textFrames.length ; k++) {
            if (doc.textFrames[k].contents != "")	{
                txt=doc.textFrames[k];

                // Black text fill to overprint
                if((txt.textRange.characterAttributes.overprintFill == false
                    && txt.textRange.characterAttributes.fillColor.cyan == 0
                    && txt.textRange.characterAttributes.fillColor.magenta == 0
                    && txt.textRange.characterAttributes.fillColor.yellow == 0
                    && txt.textRange.characterAttributes.fillColor.black == 100
                    || txt.textRange.characterAttributes.fillColor.gray == 100
                    )){
                txt.textRange.characterAttributes.overprintFill=true;
                }

                // Black text contour to overprint
                if((txt.textRange.characterAttributes.overprintStroke == false
                    && txt.textRange.characterAttributes.strokeColor.cyan == 0
                    && txt.textRange.characterAttributes.strokeColor.magenta == 0
                    && txt.textRange.characterAttributes.strokeColor.yellow == 0
                    && txt.textRange.characterAttributes.strokeColor.black == 100
                    || txt.textRange.characterAttributes.strokeColor.gray == 100
                    )){
                txt.textRange.characterAttributes.overprintStroke=true;
                }

            }
        }

        // Page properties
        for( k = 0 ; k < doc.pathItems.length; k++){
            obj = doc.pathItems[k];

            // Black fills to overprint
            if((obj.fillOverprint == false
                && obj.fillColor.cyan == 0
                && obj.fillColor.magenta == 0
                && obj.fillColor.yellow == 0
                && obj.fillColor.black == 100
                || obj.fillColor.gray == 100
                )){
            obj.fillOverprint=true;
            }

            // Black contours on overprinting
            if((obj.strokeOverprint == false
                && obj.strokeColor.cyan == 0
                && obj.strokeColor.magenta == 0
                && obj.strokeColor.yellow == 0
                && obj.strokeColor.black == 100
                || obj.strokeColor.gray == 100
                )){
            obj.strokeOverprint=true;
            }
        }

        // alert("Black outlines and fillings were set to overprint.", "The changes have been made!");
    }
}

 

 

Thanks in advance!

Regards,

Mike

 

TOPICS
Scripting

Views

149

Likes

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 3 Correct answers

Enthusiast , Nov 22, 2021 Nov 22, 2021
@femkeblanco means did you add a call to the function? eg. add this to last line of script: performBlackOverprint()  Like femkeblanco, we just need to check that before thinking of other possibilities. - Mark

Likes

Translate

Translate
Advocate , Nov 22, 2021 Nov 22, 2021
Functions have two parts: function definition and function call.  What you posted is a function definition.  You need a function call.  Add this line (either right after #target Illustrator or right at the end, after the last line): performBlackOverprint();

Likes

Translate

Translate
Advocate , Nov 22, 2021 Nov 22, 2021
Hello @m1b and @femkeblanco, Thank you both for your help!!I think I figured out, it was one of two things....I'll have to do some more testing to be for sure. 1. Even though the test file is CMYK and has pure black not set to overprint, it might have been created for something other than "print" and just set to CMYK. 2. The test file, even though it's CMYK and has pure black not set to overprint, the file went through my automated process that changes the Document color mode back and forth depe...

Likes

Translate

Translate
Advocate ,
Nov 22, 2021 Nov 22, 2021

Copy link to clipboard

Copied

The function does what it is supposed to do, i.e. change the overprint property of black paths and/or text frames from false to true.  Why do you say it doesn't do anything? 

Likes

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
Advocate ,
Nov 22, 2021 Nov 22, 2021

Copy link to clipboard

Copied

Hello @femkeblanco,

 

Thanks for replying.... when I try and run the script on a test file I have setup with some fill boxes and text with pure black applied, it doesn't change the attributes to Overprint Fill Overprint Stroke by checking them on.

 

Regards,

Mike

Likes

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
Advocate ,
Nov 22, 2021 Nov 22, 2021

Copy link to clipboard

Copied

Please excuse the obvious question, but are you calling the function (there is no function call in the code you posted)?  On the right is Overprint Preview after running the script. 

 

Untitled1.png

Likes

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
Advocate ,
Nov 22, 2021 Nov 22, 2021

Copy link to clipboard

Copied

Hello @femkeblanco,

 

please excuse my ignorance...

Re: Please excuse the obvious question, but are you calling the function (there is no function call in the code you posted)

I was trying to run the code just as I posted it, can you post an example of what you changed to get it to run?

I'm not entirely sure it's going to work, as I tested the entire code that was posted here https://gist.github.com/swasher/7eaa101abccf7b74409b

without making any changes with the exception of the pdf export preset and it doesn't work for me for some reasion.....thoughts?

 

Kind Regards,

Mike

 

Likes

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
LEGEND ,
Nov 22, 2021 Nov 22, 2021

Copy link to clipboard

Copied

When you define a function you have to call it. This is separate from defining it, and won't be included in the example. 

Likes

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
Enthusiast ,
Nov 22, 2021 Nov 22, 2021

Copy link to clipboard

Copied

@femkeblanco means did you add a call to the function? eg. add this to last line of script:

 

performBlackOverprint()

 

 Like femkeblanco, we just need to check that before thinking of other possibilities. 🙂

- Mark

Likes

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
Advocate ,
Nov 22, 2021 Nov 22, 2021

Copy link to clipboard

Copied

Functions have two parts: function definition and function call.  What you posted is a function definition.  You need a function call.  Add this line (either right after #target Illustrator or right at the end, after the last line):

 

performBlackOverprint();

Likes

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
Advocate ,
Nov 22, 2021 Nov 22, 2021

Copy link to clipboard

Copied

Hello @femkeblanco and @m1b,

 

I added the call to the function and it runs now getting the message "Black outlines and fillings were set to overprint.", "The changes have been made!"

 

but no overprint setting are changed in the document, just like when I run the entire code I got from Gethub.....so frustrating!!!...thoughts????

 

I'm running mac OSX 10.14.6

Illustrator 25.4.2

 

Regards,

Mike

Likes

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
Enthusiast ,
Nov 22, 2021 Nov 22, 2021

Copy link to clipboard

Copied

Hmm. It works for me on MacOS 12.0.1, AI 26.0.1. It would be good if you could post a sample AI file for us to test with. One that doesn't work for you.

 

Also you could try this version of the script—I've just added a counter to tell us how often it thinks it has set the overprint.

- Mark

 

 

#target Illustrator

performBlackOverprint()

function performBlackOverprint() {

    var doc = app.activeDocument;

    var count = 0;

    if (doc.documentColorSpace == DocumentColorSpace.RGB) {
        alert("The working color space is RGB. Change the document color mode to CMYK.",
            "CMYK working space required!");
    }

    else {

        // Skip Blank text frames
        for (k = 0; k < doc.textFrames.length; k++) {
            if (doc.textFrames[k].contents != "") {
                txt = doc.textFrames[k];

                // Black text fill to overprint
                if (txt.textRange.characterAttributes.overprintFill == false
                    && txt.textRange.characterAttributes.fillColor.cyan == 0
                    && txt.textRange.characterAttributes.fillColor.magenta == 0
                    && txt.textRange.characterAttributes.fillColor.yellow == 0
                    && txt.textRange.characterAttributes.fillColor.black == 100
                    || txt.textRange.characterAttributes.fillColor.gray == 100
                ) {
                    txt.textRange.characterAttributes.overprintFill = true;
                    count++;
                }

                // Black text contour to overprint
                if (txt.textRange.characterAttributes.overprintStroke == false
                    && txt.textRange.characterAttributes.strokeColor.cyan == 0
                    && txt.textRange.characterAttributes.strokeColor.magenta == 0
                    && txt.textRange.characterAttributes.strokeColor.yellow == 0
                    && txt.textRange.characterAttributes.strokeColor.black == 100
                    || txt.textRange.characterAttributes.strokeColor.gray == 100
                ) {
                    txt.textRange.characterAttributes.overprintStroke = true;
                    count++;
                }

            }
        }

        // Page properties
        for (k = 0; k < doc.pathItems.length; k++) {
            obj = doc.pathItems[k];

            // Black fills to overprint
            if (obj.fillOverprint == false
                && obj.fillColor.cyan == 0
                && obj.fillColor.magenta == 0
                && obj.fillColor.yellow == 0
                && obj.fillColor.black == 100
                || obj.fillColor.gray == 100
            ) {
                obj.fillOverprint = true;
                count++;
            }

            // Black contours on overprinting
            if ((obj.strokeOverprint == false
                && obj.strokeColor.cyan == 0
                && obj.strokeColor.magenta == 0
                && obj.strokeColor.yellow == 0
                && obj.strokeColor.black == 100
                || obj.strokeColor.gray == 100
            )) {
                obj.strokeOverprint = true;
                count++;
            }
        }

        alert(count + " items have been set to overprint.");
    }
}

 

Likes

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
Advocate ,
Nov 22, 2021 Nov 22, 2021

Copy link to clipboard

Copied

Hi @m1b ,

 

I ran your code on my test file and got "0 items have been set to overprint." for some reason I'm not able to attach\upload the Overprint-Test.ai file any suggestions?

Edit: I just posted the test file here...Please let me know if you get it as the site has only one download then the file gets deleted.

https://file.io/BHZu9ov7fkMq 

 

Regards,

Mike

Likes

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
Advocate ,
Nov 22, 2021 Nov 22, 2021

Copy link to clipboard

Copied

LATEST

Hello @m1b and @femkeblanco,

 

Thank you both for your help!!

I think I figured out, it was one of two things....I'll have to do some more testing to be for sure.

 

1. Even though the test file is CMYK and has pure black not set to overprint, it might have been created for something other than "print" and just set to CMYK.

 

2. The test file, even though it's CMYK and has pure black not set to overprint, the file went through my automated process that changes the Document color mode back and forth depending on what's being output.

 

It doesn't make a lot of sense to me that the script doesn't work on the test file, because natively I can go to Edit > Edit Colors > Overprint Black and change the overprint settings that way.

 

Regards,

Mike

Likes

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