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.


Script to replace a tinted swatch with a nontinted swatch

Community Beginner ,
Nov 24, 2021 Nov 24, 2021

Copy link to clipboard

Copied

I have a script where I'm replacing swatches with others and I'm not able to replace a tinted swatch, it just ignores it. Any tips to get this script to find my 90% tint swatch and replace it?

 

var myDoc = app.activeDocument;

//replace swatches
try { myDoc.colors.item("PANTONE 426 C 90%").remove("PANTONE 426 C");}
catch (e) {}
TOPICS
How to, Scripting

Views

60

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 1 Correct answer

Enthusiast , Nov 24, 2021 Nov 24, 2021
Hi @LynxKx, here's some code to point you in the right direction. I've made a function that removes all tints of a particular color. The main points are that "tints" are different objects to "colors", and have a baseColor property that points to the actual color.- Mark removeTintsOfColor(app.activeDocument, 'MyColor'); function removeTintsOfColor(doc, colorOrName) { var color; if (colorOrName.constructor.name == 'String') { color = doc.swatches.itemByName(colorOrName); } el...

Likes

Translate

Translate
Enthusiast ,
Nov 24, 2021 Nov 24, 2021

Copy link to clipboard

Copied

Hi @LynxKx, here's some code to point you in the right direction. I've made a function that removes all tints of a particular color. The main points are that "tints" are different objects to "colors", and have a baseColor property that points to the actual color.

- Mark

 

removeTintsOfColor(app.activeDocument, 'MyColor');


function removeTintsOfColor(doc, colorOrName) {
    var color;
    if (colorOrName.constructor.name == 'String') {
        color = doc.swatches.itemByName(colorOrName);
    } else if (colorOrName.constructor.name == 'Color') {
        color = colorOrName;
    }
    if (color == undefined || !color.isValid) return;
    var tints = doc.tints;
    for (var i = tints.length - 1; i >= 0; i--) {
        if (tints[i].baseColor == color)
            tints[i].remove();
    }
}

 

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
Community Beginner ,
Nov 24, 2021 Nov 24, 2021

Copy link to clipboard

Copied

LATEST

perfect! thank you so much!!

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