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

Change layer name by name text in group

Explorer ,
Sep 26, 2022 Sep 26, 2022

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.

polotrobo_0-1664185980609.pngpolotrobo_1-1664185985174.png

 

 

PM

TOPICS
Draw and design , Scripting , Third party plugins , Tools

Views

283

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

Enthusiast , Sep 26, 2022 Sep 26, 2022

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
...

Votes

Translate

Translate
Adobe
Community Expert ,
Sep 26, 2022 Sep 26, 2022

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.

Best regards

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
Enthusiast ,
Sep 26, 2022 Sep 26, 2022

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]);
      }
    }
  }
}

group-name-from-text.gif

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
Explorer ,
Sep 27, 2022 Sep 27, 2022

Copy link to clipboard

Copied

Amazing !! Thank you so much @Sergey Osokin and @Charu Rajput 

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
Enthusiast ,
Mar 16, 2023 Mar 16, 2023

Copy link to clipboard

Copied

LATEST

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
GroupNameByTopText.gif

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