• 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 for changing color values

Explorer ,
Nov 12, 2021 Nov 12, 2021

Copy link to clipboard

Copied

Hi, I am not much into scripting in indesign, but this can be done for sure. Thanks in advance. 🙂

 

I would like to have tool to change cmyk values of named colors C1, C2, C3, C4 in active document and the values should be from some .ini or .txt document. 

- so I will be able to change values once and use it one month and change it again for another month. 

 

I found here this from @typolis but I dont know how to use it. 

app.activeDocument.colors.item("Color 1").colorValue = [0,20,80,0];

 

*I opened script editor, but what to write there I dont know. 

TOPICS
How to , Scripting

Views

1.8K

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

The same question for creating Lab colors from a .cvs file came up the other day—the thread is here:

 

https://community.adobe.com/t5/indesign-discussions/script-for-exporting-lab-color-swatch-values-to-excel-csv/m-p/12515665#M452867

 

The Javascript for a CMYK version is below, where the CSV spreadsheet is saved to your desktop and named CMYKColors.csv. The format of the spreadsheet needs to be this:

 

Screen Shot 16.png

The compiled JavaScript and example spreadsheet is here:

https://shared-assets.adobe.com/link/271a260c-5f48-4cec-5daa-9f324764de24

...

Votes

Translate

Translate
Community Expert ,
Nov 12, 2021 Nov 12, 2021

Copy link to clipboard

Copied

app.activeDocument.colors.item("C1").colorValue = [ 0,20,80,0 ];

 

Is this clearer now?

The values in the brackets are the percentages for CMYK.

 

Regards,
Uwe Laubender

( ACP )

 

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
Explorer ,
Nov 12, 2021 Nov 12, 2021

Copy link to clipboard

Copied

Hi, I understand that Color1 is C1 but it is not working in that way I can change one source to change colors in two devices at once. But thanks for your interest. 

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 Expert ,
Nov 12, 2021 Nov 12, 2021

Copy link to clipboard

Copied

app.activeDocument.colors.item("C1").colorValue =

 

Is there a swatch named C1 saved in the active document? The line doesn’t create a swatch, it sets the CMYK values of an existing swatch named "C1"

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
Explorer ,
Nov 12, 2021 Nov 12, 2021

Copy link to clipboard

Copied

But as I understand this I have to change values right into the script not into some external source to get the values. I am just trying it right now if the script below will work if I will have those C1 C2 C3 in paragraph styles. Hope will. Assume as you write, that this script is changing values of created colors. 

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
Explorer ,
Nov 12, 2021 Nov 12, 2021

Copy link to clipboard

Copied

The scipt below is working when those colors are aplied in paragraph styles! This is awesome!

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 Expert ,
Nov 12, 2021 Nov 12, 2021

Copy link to clipboard

Copied

The same question for creating Lab colors from a .cvs file came up the other day—the thread is here:

 

https://community.adobe.com/t5/indesign-discussions/script-for-exporting-lab-color-swatch-values-to-...

 

The Javascript for a CMYK version is below, where the CSV spreadsheet is saved to your desktop and named CMYKColors.csv. The format of the spreadsheet needs to be this:

 

Screen Shot 16.png

The compiled JavaScript and example spreadsheet is here:

https://shared-assets.adobe.com/link/271a260c-5f48-4cec-5daa-9f324764de24

 

This is the code:

 

 

var path = File(Folder.desktop + "/CMYKColors.csv");
var cTable = readFile(path);
//split the table into an array of rows
var r = cTable.split("\n");

var doc = app.activeDocument;
app.scriptPreferences.measurementUnit = MeasurementUnits.INCHES
var c, ns;

for (var i = 1; i < r.length; i++){
    //split the row into an array of cells
    c = r[i].split(",");
    try {
        ns = makeSwatch(doc, c[0]); 
        ns.model = ColorModel.PROCESS;
        ns.space = ColorSpace.CMYK;
        ns.colorValue = [Number(c[1]),Number(c[2]),Number(c[3]),Number(c[4])];
    }catch(e) {}  
};   


/**
* Read a text file 
* @Param the file’s path 
* @Return the file’s contents 
* 
*/

function readFile(p) {
	var f = new File(p);
	f.open("r");  
	var x = f.read();  
	f.close();
	return x; 
}


/**
* Makes a new swatch 
* @Param the document to add the swatch to 
* @Param swatch name 
* @Return the new or existingswatch 
* 
*/
function makeSwatch(d, n){
    var s;
    try {
        d.colors.add({name:n});
    }catch(e) {
        s = d.colors.itemByName(n);
    } 
    return d.colors.itemByName(n);
}

 

 

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
Explorer ,
Nov 12, 2021 Nov 12, 2021

Copy link to clipboard

Copied

This is amazing, I just tried it and it works well! 

 

Two more questions:

do you think it will work if I will have the csv source on server and the all path will be from server? 

var path = File(Folder.desktop + "/path here/folder/folder/folder/CMYKColors.csv");

 

And if in the csv should be just those values or there can be description also in another rows? 

 

I am amazed! Thanks a lot!  

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 Expert ,
Nov 12, 2021 Nov 12, 2021

Copy link to clipboard

Copied

The format of the CSV has to be exactly as it is in my sample—you can include any number of color rows.

 

do you think it will work if I will have the csv source on server and the all path will be from server?

var path = File(Folder.desktop + "/path here/folder/folder/folder/CMYKColors.csv");

 

That would be the path to a subfolder on the desktop. Folder.desktop + is a javascript shortcut to the desktop root folder–you don’t need to know the absolute path (e.g., startup/Users/username/Desktop)

 

You could also use an open dialog to get the file path. This will display the chosen file’s path as an alert:

 

 

 

var path = File.openDialog("Choose a CSV file");
alert(path)

 

 

A server path might be something like:

 

 

var path = File("/Server/Users/username/Documents/Color/CMYKColors.csv");

 

 

 

 

 

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
Explorer ,
Nov 12, 2021 Nov 12, 2021

Copy link to clipboard

Copied

I tried to copy and paste the path from explorer, it doesnot work, but as I changed the backslash to / everything go great, it finds the way on server. Very appreciate this! 

 

I am trying to make this the most seamless for coleagues and it will be easier without any dialog box, but if they will like, can be added. Big Thanks! Saved my day!

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 Expert ,
Nov 12, 2021 Nov 12, 2021

Copy link to clipboard

Copied

LATEST

The other way to serve the .csv file would be to make a folder in your local Creative Cloud Files folder, and invite the InDesign users to sync to the folder and its contents. In that case a version of your csv CMYK edits would sync to everyone’s Creative Cloud Files folder —right-click the folder, choose View on Website to send the invites.

 

The file path for that would be something like

 

 

 

var path = File("~/Creative%20Cloud%20Files/Color/CMYKColors.csv");

 

 

Where "~/Creative%20Cloud%20Files/... is the root CCF folder

 

 

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