Skip to main content
Known Participant
August 26, 2022
Answered

Script to change of the group of multiple grouped text

  • August 26, 2022
  • 2 replies
  • 285 views

Hello Everyone,

 

I have previously posted the query in changing the color of the selected text in group and outside the group and I got answer aswell.

 

But, I got a new problem that the script was not changing the selected group item containing mutliple group item of texts inside that group.

 

docRef = app.activeDocument;

var color1 = new CMYKColor();
color1.cyan = 100;
color1.magenta = 0;
color1.yellow = 0;
color1.black = 0;
var spot = docRef.spots.add();
spot.color = color1;
spot.colorType = ColorModel.SPOT;
spot.name = "Keyline Blue";

var selectedObjects = docRef.selection;

for (var i = 0; i < selectedObjects.length; i++) {
    if (selectedObjects[i].typename == "TextFrame") {
        selectedObjects[i].textRange.fillColor = spot.color;
    } else if (selectedObjects[i].typename == "GroupItem") {
        for (var t = 0; t < selectedObjects[i].textFrames.length; t++) {
            selectedObjects[i].textFrames[t].textRange.fillColor = spot.color;
        }
    }
}

 

 

Help me in this concern, I am attaching the script that work for the one group item, and also am attaching the sample there its not working.

This topic has been closed for replies.

2 replies

Charu Rajput
Community Expert
Community Expert
August 26, 2022

Hi,

You need to run recursively for all textframes inside the group.

docRef = app.activeDocument;

var color1 = new CMYKColor();
color1.cyan = 100;
color1.magenta = 0;
color1.yellow = 0;
color1.black = 0;
var spot = docRef.spots.add();
spot.color = color1;
spot.colorType = ColorModel.SPOT;
spot.name = "Keyline Blue";

var selectedObjects = docRef.selection;
changeColor(selectedObjects);


function changeColor(items) {
    for (var i = 0; i < items.length; i++) {
        if (items[i].typename == "TextFrame") {
            items[i].textRange.fillColor = spot.color;
        } if (items[i].typename == "GroupItem") {
            changeColor(items[i].pageItems);
        }
    }
}

Hope above version will work for you.

Best regards