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

InDesign Script

New Here ,
Sep 21, 2023 Sep 21, 2023

How to generate swatch values in indesign with script?

TOPICS
Scripting
660
Translate
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 ,
Sep 21, 2023 Sep 21, 2023

Hi@innovative_amazement5DC5 ,

do you want to add a color to the swatches panel or do you want to modify a given one?

 

Look into DOM documentation for InDesign:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Color.html#d1e68975

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Colors.html

 

Here a code sample for adding a named process color in CMYK with C: 100, M: 0, Y: 50, K: 0:

 

app.documents[0].colors.add
(
	
	{
		name : "myColorName" ,
		space :  ColorSpace.CMYK ,
		model : ColorModel.PROCESS ,
		colorValue : [ 100 , 0 , 50 , 0 ]
	}

);



Regards,
Uwe Laubender
( Adobe Community Expert )

Translate
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
New Here ,
Sep 21, 2023 Sep 21, 2023

@Laubender  Thank you for the reply. I am looking for a script where you can generate the CMYK, RGB and HEX values for the colours. For example there are multiple colours used and I need the CMYK, RGB and HEX values, so with the help of the script I need the values to be generated, where I can use it in Brand Book showing the colour values.

Instead of typing the whole CMYK, RGB and HEX values, with just 1 click of the script I need those.

There is a script for Adobe Illustrator, where you select all the colours whcih are on art board and then you run the script and automatically below the colours we get the CMYK, RGB and HEX values in text format which can be editable.

Thank you.

Translate
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
Engaged ,
Sep 21, 2023 Sep 21, 2023

Here is a quick stab at it. It only checks for RGB and CMYK colors, but it should be easy to add in the rest.

 

const app = require('indesign').app;
const ColorSpace = require('indesign').ColorSpace;
var doc = app.activeDocument;
var select = doc.selection;

for(x=0;x<select.length;x++){
if(select[x].fillColor.space == 'RGB'){
var tempColor = doc.colors.add(select[x].fillColor);
tempColor.space = ColorSpace.CMYK;
var colorText = doc.textFrames.add();
var hexNumber = [];
if(select[x].fillColor.colorValue[0].toString(16).length == 1){
hexNumber.push("0" + select[x].fillColor.colorValue[0].toString(16));
}else{
hexNumber.push(select[x].fillColor.colorValue[0].toString(16));
}
if(select[x].fillColor.colorValue[1].toString(16).length == 1){
hexNumber.push("0" + select[x].fillColor.colorValue[1].toString(16));
}else{
hexNumber.push(select[x].fillColor.colorValue[1].toString(16));
}
if(select[x].fillColor.colorValue[2].toString(16).length == 1){
hexNumber.push("0" + select[x].fillColor.colorValue[2].toString(16));
}else{
hexNumber.push(select[x].fillColor.colorValue[2].toString(16));
}
colorText.geometricBounds = [select[x].geometricBounds[2]+0.0625,select[x].geometricBounds[1],select[x].geometricBounds[2]+0.75,select[x].geometricBounds[3]]
colorText.contents = select[x].fillColor.colorValue[0] + "/" + select[x].fillColor.colorValue[1] + "/" + select[x].fillColor.colorValue[2] + "\n";
colorText.contents += hexNumber[0] + hexNumber[1] + hexNumber[2] + "\n";
colorText.contents += parseInt(tempColor.colorValue[0]) + "/" + parseInt(tempColor.colorValue[1]) + "/" + parseInt(tempColor.colorValue[2]) + "/" + parseInt(tempColor.colorValue[3]);
tempColor.remove();
}
if(select[x].fillColor.space == 'CMYK'){
var tempColor = doc.colors.add(select[x].fillColor);
tempColor.space = ColorSpace.RGB;
var colorText = doc.textFrames.add();
const rgbNumber = [
parseInt(tempColor.colorValue[0]),
parseInt(tempColor.colorValue[1]),
parseInt(tempColor.colorValue[2])
];
var hexNumber = [];
if(rgbNumber[0].toString(16).length == 1){
hexNumber.push("0" + rgbNumber[0].toString(16));
}else{
hexNumber.push(rgbNumber[0].toString(16));
}
if(rgbNumber[1].toString(16).length == 1){
hexNumber.push("0" + rgbNumber[1].toString(16));
}else{
hexNumber.push(rgbNumber[1].toString(16));
}
if(rgbNumber[2].toString(16).length == 1){
hexNumber.push("0" + rgbNumber[2].toString(16));
}else{
hexNumber.push(rgbNumber[2].toString(16));
}
colorText.geometricBounds = [select[x].geometricBounds[2]+0.0625,select[x].geometricBounds[1],select[x].geometricBounds[2]+0.75,select[x].geometricBounds[3]]
colorText.contents = parseInt(tempColor.colorValue[0]) + "/" + parseInt(tempColor.colorValue[1]) + "/" + parseInt(tempColor.colorValue[2]) + "\n";
colorText.contents += hexNumber[0] + hexNumber[1] + hexNumber[2] + "\n";
colorText.contents += select[x].fillColor.colorValue[0] + "/" + select[x].fillColor.colorValue[1] + "/" + select[x].fillColor.colorValue[2] + "/" + select[x].fillColor.colorValue[3];
tempColor.remove();
}

}
Translate
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 ,
Sep 24, 2023 Sep 24, 2023
LATEST

For example there are multiple colours used and I need the CMYK, RGB and HEX values, so with the help of the script I need the values to be generated, where I can use it in Brand Book showing the colour values.

 

Hi @innovative_amazement5DC5 , There are a few things you have to consider when attempting to make color conversions either via scripting or the UI. If the source master color is device dependent—either CMYK or RGB—the document’s assigned color profiles will affect the color appearance and conversion values. For example the CMYK color 20|20|20|20 will have a different appearance depending on the assigned CMYK profile—US Sheetfed Coated will have a considerably darker appearnace than US Web Coated SWOP. Also the conversion to RGB would produce different values depending on the destination RGB profile—the conversion to sRGB would be different than the conversion to AdobeRGB.

 

You might consider defining the master source colors as Lab—the Pantone+ Solid Ink libraries are defined as Lab. A Lab color’s appearance is not affected by the document’s assigned profiles. This thread has more detail and a script option:

 

https://community.adobe.com/t5/indesign-discussions/branding-color-guide/td-p/10818696

 

 

Translate
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 ,
Sep 22, 2023 Sep 22, 2023

@innovative_amazement5DC5 said "… For example there are multiple colours used and I need the CMYK, RGB and HEX values, so with the help of the script I need the values to be generated, where I can use it in Brand Book showing the colour values."

 

Hm.

Just to clarify, you need the actual values, name, color space, color model, color values, of a given fill color when you e.g. select one or more rectangles. Written to a text frame below the selected objects.

 

You do not expect any values from color transformations like RGB to CMYK, HSB to CMYK, Lab to CMYK, spot colors to CMYK, don't you?

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Translate
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