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

InDesign Script to manage swatches

Contributor ,
Nov 24, 2021 Nov 24, 2021

Copy link to clipboard

Copied

I put together a script to automatically import swatches and styles from another InDesign file. Is there anything extra I can add to the code that would keep it from duplicating my CMYK blend? it duplicates that color if i already have it in a file.

 

 

I'm also replacing old swatches with new and cant eliminate the tint swatch thats in my file. How do i include the tint swatch in my code to remove or replace it.

 

var myDoc = app.activeDocument;
var preFile = File.openDialog ("Select file");

//load swatches
var _loadSwatches = preFile;
if ( _loadSwatches != null ) {
try { app.activeDocument.loadSwatches ( _loadSwatches ) }
catch ( _ ) { alert ( _ ) }
}

//replace swatches
try { myDoc.colors.item("PANTONE Neutral Black C 90%").remove("PANTONE 426 C");}
catch (e) {}

 

 

 

TOPICS
How to , Scripting

Views

1.1K

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

Contributor , Nov 29, 2021 Nov 29, 2021

If anyone sees this later needing a solution ...  If I load swatch from an .ase file it will duplicate any CMYK blend swatches I may already have,  however if I import swatches from an InDesign file, it will not duplicate the swatch.

Votes

Translate

Translate
Contributor , Nov 29, 2021 Nov 29, 2021

i also got this script from someone that will eliminate tint swatches

//remove swatch tint
removeTintsOfColor(myDoc, "PANTONE Neutral Black C");
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 
...

Votes

Translate

Translate
Contributor , Sep 08, 2022 Sep 08, 2022

totally! in the same InDesign file you saved the swatches in, add any new styles so they can be pulled in at the same time

 

var myDoc = app.activeDocument;
var preFile = File.openDialog ("Select file");
var paraStyles = myDoc.allParagraphStyles;
var charStyles = myDoc.allCharacterStyles;

//load swatches
var _loadSwatches = preFile;
if ( _loadSwatches != null ) {
try { app.activeDocument.loadSwatches ( _loadSwatches ) }
catch ( _ ) { alert ( _ ) }}

//load styles
myDoc.importStyles(ImportFormat.P
...

Votes

Translate

Translate
Contributor ,
Nov 24, 2021 Nov 24, 2021

Copy link to clipboard

Copied

disregard duplicating swatch question, I'm not able to reproduce the issue I was having and i'm able to import swatches without duplicating any.

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 29, 2021 Nov 29, 2021

Copy link to clipboard

Copied

If anyone sees this later needing a solution ...  If I load swatch from an .ase file it will duplicate any CMYK blend swatches I may already have,  however if I import swatches from an InDesign file, it will not duplicate the swatch.

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 29, 2021 Nov 29, 2021

Copy link to clipboard

Copied

i also got this script from someone that will eliminate tint swatches

//remove swatch tint
removeTintsOfColor(myDoc, "PANTONE Neutral Black C");
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("PANTONE Neutral Black C");}}

 

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 ,
Sep 08, 2022 Sep 08, 2022

Copy link to clipboard

Copied

Hello, I am very new to scripts and am not seeing any solutions for what I am trying to do. Hoping you can help possibly? We have proposals and there are about 30+/- color swatches. Many are duplicates. I am hoping there is a way to do the following with scripting: 

  • Import two .ASE files
  • Identify swatch by specified name > delete swatch > replace swatch with new color
    (ie: after importing ASE file the script will then look for custom names like
    "Cyan 100" > Delete/Replace with "Pantone 2925C"
    "65K 12" > Delete/Replace with "65K"
    "Pantone 2925C Copy" > Delete/Replace with "Pantone 2925C" 

Any help would be appreciated! I am not the best at reading javascript and hoping to learn. Thank you!

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 ,
Sep 08, 2022 Sep 08, 2022

Copy link to clipboard

Copied

I like to load swatches from an Indesign file b/c it wont duplicate swatches as copies (just create an InDesign file with all the new swatches you want to pull in) Below is some code that will prompt you to open an InDesign, you will select it and the script will load the swatches from that file and then replace out the swatches you specify.  let me know how this works!

 

var myDoc = app.activeDocument;
var preFile = File.openDialog ("Select file");

//load swatches
var _loadSwatches = preFile;
if ( _loadSwatches != null ) {
try { app.activeDocument.loadSwatches ( _loadSwatches ) }
catch ( _ ) { alert ( _ ) }}

//replace swatches
try { myDoc.colors.item("Cyan 100").remove("PANTONE 2925 C");}catch (e) {}
try { myDoc.colors.item("65K 12").remove("65K");}catch (e) {}
try { myDoc.colors.item("OLD").remove("NEW");}catch (e) {}


// Done
alert("Abracadabra!!");

 

 

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 ,
Sep 08, 2022 Sep 08, 2022

Copy link to clipboard

Copied

This worked like a dream thank you so much! Is this possible with paragraph and character styles?

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 ,
Sep 08, 2022 Sep 08, 2022

Copy link to clipboard

Copied

totally! in the same InDesign file you saved the swatches in, add any new styles so they can be pulled in at the same time

 

var myDoc = app.activeDocument;
var preFile = File.openDialog ("Select file");
var paraStyles = myDoc.allParagraphStyles;
var charStyles = myDoc.allCharacterStyles;

//load swatches
var _loadSwatches = preFile;
if ( _loadSwatches != null ) {
try { app.activeDocument.loadSwatches ( _loadSwatches ) }
catch ( _ ) { alert ( _ ) }}

//load styles
myDoc.importStyles(ImportFormat.PARAGRAPH_STYLES_FORMAT, preFile);
myDoc.importStyles(ImportFormat.CHARACTER_STYLES_FORMAT, preFile);
myDoc.importStyles(ImportFormat.OBJECT_STYLES_FORMAT, preFile);
myDoc.importStyles(ImportFormat.TABLE_AND_CELL_STYLES_FORMAT, preFile);

//replace swatches
try { myDoc.colors.item("OLD").remove("NEW");}catch (e) {}
try { myDoc.colors.item("OLD").remove("NEW");}catch (e) {}
try { myDoc.colors.item("OLD").remove("NEW");}catch (e) {}


// Rename styles
for (a = 2; a < paraStyles.length; a++) {
    if (paraStyles[a].name == "OLD") { paraStyles[a].name = "NEW"; }
    if (paraStyles[a].name == "OLD") { paraStyles[a].name = "NEW"; }
    if (paraStyles[a].name == "OLD") { paraStyles[a].name = "NEW"; }}
for (a = 2; a < charStyles.length; a++) {
    if (charStyles[a].name == "OLD") { charStyles[a].name = "NEW"; }
    if (charStyles[a].name == "OLD") { charStyles[a].name = "NEW"; }
    if (charStyles[a].name == "OLD") { charStyles[a].name = "NEW"; }} 

// Replace styles in a group if file for sure has all of them, if one is missing then it will skip the rest
try{    
    paraStyles.item("OLD").remove(paraSyles.item("NEW"));
    charStyles.item("OLD").remove(charSyles.item("NEW"));
    paraStyles.item("OLD").remove(paraSyles.item("NEW"));
}catch(e){}

// Replace styles individually
try { paraStyles.item("OLD").remove(paraSyles.item("NEW");}catch (e) {}
try { charStyles.item("OLD").remove(paraSyles.item("NEW");}catch (e) {}

// Done
alert("Alakazam!");

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 ,
Sep 08, 2022 Sep 08, 2022

Copy link to clipboard

Copied

Oh my you just saved me so much time I have been searching and trying to figure this out! Thank you SO 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
Contributor ,
Sep 08, 2022 Sep 08, 2022

Copy link to clipboard

Copied

LATEST

absolutely! this community helped me learn so much about javascript to make working more efficient! I'm glad Ive learned enough to contribute!

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