Skip to main content
Known Participant
June 20, 2024
Question

colors

  • June 20, 2024
  • 3 replies
  • 331 views

I have an InDesign 2024 document with 778 pages that includes 12 colors on all pages. I want to change these 12 colors to another set of 12 colors using a script.

This topic has been closed for replies.

3 replies

Inspiring
June 21, 2024

With this script you can replace the desired colour with a saved colour (ASE file) in one go. However, it only works with one colour at a time. You just have to do it twelve times.
It actually only simplifies the principle that rob day has already written

 

//DESCRIPTION:An imported color should replace an existing color
//Version: 1.0
//Autor: SteigART

#target Indesign

if(app.documents.length == 0){
    alert("No Document open");
}else{
    var doc = app.activeDocument;
    main(doc);
}

function main(doc){
    // A list of all colors in the document (required for comparison with the new list);
    var allColorOld = doc.swatches.everyItem().name;

    //Create a dialog window
    var dial = app.dialogs.add();
    dial.name = "Select the color to be replaced";
    var dialColum = dial.dialogColumns.add();
    var dropdown = dialColum.dropdowns.add();
    dropdown.stringList = allColorOld;

    // Dialog start
    var dialResult = dial.show();

    //Define the evaluation of the dialog and the color to be deleted
    if(dialResult){
        var selColor = doc.swatches[dropdown.selectedIndex].name;

        //Release dialog memory
        dial.destroy();

        // Load Color in Indesign
        importColor(doc, selColor, allColorOld);

    }else{
        dial.destroy();
    }

}


function importColor(doc, selColor, allColorOld){
    // Select color file (ASE-Datei)
    var ColorFile = File.openDialog("Choose an ASE file to import", "*.ase");
    
    // Check if the user has selected a file
    if(ColorFile === null){
        alert("No color file selected");
        return;
    }
    
    //Check if the selected file exists
    if(!ColorFile.exists){
        alert("The file does not exist: " + ColorFile.fullName);
        return;
    }
    
    // Import color from the ASE file
    doc.loadSwatches(ColorFile);
    
    // List with all colors in the document including the newly imported
    var allColorNew = doc.swatches.everyItem().name;

    // Compare color lists with each other and save the new color in variable
    for(i=0; i<allColorNew.length; i++){
        if(allColorOld[i] != allColorNew[i]){
            var newColor = allColorNew[i];
        }
    }

    // Create variable of the color selected at the beginning
    var delColor = doc.swatches.itemByName(selColor);

    // Delete the selected color and replace it with the imported one
    delColor.remove(newColor);
}

 

Derek Cross
Community Expert
Community Expert
June 20, 2024

Do you mean CMYK plus 8 spot colours?

rob day
Community Expert
Community Expert
June 20, 2024

Hi @aghanjar16430960 , Create or load the 12 new Swatches. When you delete a Swatch that is being used, you will be prompted to choose a replacement. It will take less time to manually replace the used colors than write a script.