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

Script to replace a tinted swatch with a nontinted swatch

Contributor ,
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

252

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 , 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
...

Votes

Translate

Translate
Community Expert ,
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();
    }
}

 

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

Copy link to clipboard

Copied

LATEST

perfect! thank you so much!!

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