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

Layer colour label change script

Contributor ,
Jan 17, 2024 Jan 17, 2024

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

 

TOPICS
How to , Scripting
579
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

correct answers 1 Correct answer

Community Expert , Jan 17, 2024 Jan 17, 2024
// 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++) {
        
...
Translate
Community Expert ,
Jan 17, 2024 Jan 17, 2024

Existing colors of what? The label color?

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
Contributor ,
Jan 17, 2024 Jan 17, 2024

Yes, in the layer options.

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 ,
Jan 17, 2024 Jan 17, 2024

tmp_4b4ba281-9117-426f-9c62-4b0c60453a3e.png

Did u mentioned this?

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
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 ,
Jan 17, 2024 Jan 17, 2024
// 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!

Mike Witherell
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
Contributor ,
Jan 18, 2024 Jan 18, 2024
LATEST

Perfect, 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