Copy link to clipboard
Copied
Hello everyone,
I would like to run a script which change the group's name in a specific layer (layer's name: "VEI") by a text in the group.
Exemple: the group is called " <Groupe> " and in that group I have a text called PEH and a text called "PEV" in another group called "<Groupe>" too. I would like to have the groupe renamed by "PEH" when I have a "PEH" text in the groupe or by "PEV" when I have a "PEV" text in the group.)
Sorry for the understanding, I tried to be the more cleaver I could.
PM
Added recursive text search in a group to your code.
var doc = app.activeDocument;
var lyr = doc.layers['VEI'];
var grps = lyr.groupItems;
for (var g = 0; g < grps.length; g++) {
var tf = getFirstTF(grps[g]);
grps[g].name = tf.contents;
}
// Recursive search of topmost TextFrame
function getFirstTF(grp) {
if (grp.textFrames.length) {
return grp.textFrames[0];
} else {
for (var i = 0; i < grp.pageItems.length; i++) {
if (grp.pageItems[i].typename === 'GroupItem') {
r
...
Copy link to clipboard
Copied
Hi,
Try following code
var doc = app.activeDocument;
var _layer = doc.layers['VEI'];
var _groups = _layer.groupItems;
for (var g = 0; g < _groups.length; g++) {
var _textFrame = _groups[g].textFrames[0];
_groups[g].name = _textFrame.contents;
}
Above script works assuming your group contains only single textframe.
Copy link to clipboard
Copied
Added recursive text search in a group to your code.
var doc = app.activeDocument;
var lyr = doc.layers['VEI'];
var grps = lyr.groupItems;
for (var g = 0; g < grps.length; g++) {
var tf = getFirstTF(grps[g]);
grps[g].name = tf.contents;
}
// Recursive search of topmost TextFrame
function getFirstTF(grp) {
if (grp.textFrames.length) {
return grp.textFrames[0];
} else {
for (var i = 0; i < grp.pageItems.length; i++) {
if (grp.pageItems[i].typename === 'GroupItem') {
return getFirstTF(grp.pageItems[i]);
}
}
}
}
Copy link to clipboard
Copied
Amazing !! Thank you so much @Sergey Osokin and @Charu Rajput
Copy link to clipboard
Copied
The updated version detects line-breaks and converts them to spaces in the group name. If nothing is selected, all groups in the active layer are renamed.
https://gist.github.com/creold/c5c36e9e6daf49082437aea5059e0462