Copy link to clipboard
Copied
I have an InDesign document with 3 layers -
US TEXT BLACK
UK TEXT BLACK
CMYK
Is it possible to write a script that would change the existing colours to the below -
US TEXT BLACK - Red
UK TEXT BLACK - Green
CMYK - Light blue
// Specify the names of the layers and their corresponding color labels
var layerInfo = [
{ name: "US TEXT BLACK", colorLabel: UIColors.RED },
{ name: "UK TEXT BLACK", colorLabel: UIColors.GREEN },
{ name: "CMYK", colorLabel: UIColors.LIGHT_BLUE }
];
// Function to change the color options of layers
function changeLayersColorLabels(layersInfo) {
// Get a reference to the active document
var doc = app.activeDocument;
for (var i = 0; i < layersInfo.length; i++) {
...
Copy link to clipboard
Copied
Existing colors of what? The label color?
Copy link to clipboard
Copied
Yes, in the layer options.
Copy link to clipboard
Copied
Did u mentioned this?
Copy link to clipboard
Copied
// Specify the names of the layers and their corresponding color labels
var layerInfo = [
{ name: "US TEXT BLACK", colorLabel: UIColors.RED },
{ name: "UK TEXT BLACK", colorLabel: UIColors.GREEN },
{ name: "CMYK", colorLabel: UIColors.LIGHT_BLUE }
];
// Function to change the color options of layers
function changeLayersColorLabels(layersInfo) {
// Get a reference to the active document
var doc = app.activeDocument;
for (var i = 0; i < layersInfo.length; i++) {
var layerInfo = layersInfo[i];
var layerName = layerInfo.name;
var colorLabel = layerInfo.colorLabel;
// Find the layer by name
var targetLayer = doc.layers.itemByName(layerName);
// Check if the layer exists
if (targetLayer.isValid) {
// Set the color label of the layer
targetLayer.properties = { layerColor: colorLabel };
$.writeln("Color option of layer '" + layerName + "' changed to specified color label");
} else {
$.writeln("Layer '" + layerName + "' not found.");
}
}
}
// Call the function to change the color options of layers
changeLayersColorLabels(layerInfo);
This version seems to work!
Copy link to clipboard
Copied
Perfect, thank you!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now