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

Layer colour label change script

Contributor ,
Jan 17, 2024 Jan 17, 2024

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

 

TOPICS
How to , Scripting

Views

247

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 , 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++) {
        
...

Votes

Translate

Translate
Community Expert ,
Jan 17, 2024 Jan 17, 2024

Copy link to clipboard

Copied

Existing colors of what? The label color?

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

Copy link to clipboard

Copied

Yes, in the layer options.

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

Copy link to clipboard

Copied

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

Did u mentioned this?

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.

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

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!

Mike Witherell

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

Copy link to clipboard

Copied

LATEST

Perfect, thank you!

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