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

Script - Counting groups in a specific layer

Explorer ,
Sep 23, 2022 Sep 23, 2022

Copy link to clipboard

Copied

Hello everyone,

polotrobo_1-1663934534091.png

I have to count some groups in a specific layer. I would like to run a script which search in the layer called "VEI" to find all the groups with "PEH" et "PEV" included in order to count them by adding numbers.

polotrobo_0-1663934433516.png

 

Thank you
PM

 

TOPICS
Scripting , Tools

Views

269

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

Advocate , Sep 25, 2022 Sep 25, 2022

Bonjour Polotrobo,

Le texte en position 0 est modifié,selon la disposition en ligne de gauche à droite et du haut vers le bas...

 

// JavaScript Document for Illustrator
// INIT --------------------
var layerName = "VEY";
var Grp1Name = "PEH";
var Grp2Name = "PEV";
// -------------------------
function main () {
  var docRef = activeDocument;
  var lay = docRef.layers[layerName];
  var grps = [];
    for (var i = 0; i < lay.groupItems.length; i++) {
         grps.push(lay.groupItems[i]);
    }
    
...

Votes

Translate

Translate
Adobe
LEGEND ,
Sep 23, 2022 Sep 23, 2022

Copy link to clipboard

Copied

This is hard-coded to search only for the group names you've given. It could be changed to be more dynamic:

 

function countGroups() {
    var aDoc = app.activeDocument;
    var myLayer = prompt('Set Layer', 'VEI');
    var ii = 0;

    for (i = 0; i < aDoc.layers[myLayer].groupItems.length; i++) {
        var myGroup = aDoc.layers[myLayer].groupItems[i];
        if (myGroup.name == 'PEH' || myGroup.name == 'PEV') {
            ii = ii + 1;
        }
    }
    alert(ii);
}
countGroups();

 

EDIT:
This version allows you to set the "Group" names within the script:

function countGroups() {
    var aDoc = app.activeDocument;
    var myLayer = prompt('Set Layer', 'VEI'),
    myGroup1 = prompt('Set Group1', 'PEH'),
    myGroup2 = prompt('Set Group1', 'PEV');
    var ii = 0;

    for (i = 0; i < aDoc.layers[myLayer].groupItems.length; i++) {
        var myGroup = aDoc.layers[myLayer].groupItems[i];
        if (myGroup.name == myGroup1 || myGroup.name == myGroup2) {
            ii = ii + 1;
        }
    }
    alert(ii);
}
countGroups();

 

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
Advocate ,
Sep 25, 2022 Sep 25, 2022

Copy link to clipboard

Copied

Bonjour Polotrobo,

Le texte en position 0 est modifié,selon la disposition en ligne de gauche à droite et du haut vers le bas...

 

// JavaScript Document for Illustrator
// INIT --------------------
var layerName = "VEY";
var Grp1Name = "PEH";
var Grp2Name = "PEV";
// -------------------------
function main () {
  var docRef = activeDocument;
  var lay = docRef.layers[layerName];
  var grps = [];
    for (var i = 0; i < lay.groupItems.length; i++) {
         grps.push(lay.groupItems[i]);
    }
     grps.reverse();
  var k = 1, grp, text, h, H;
     for (i = 0; i < grps.length; i++) {
        grp = grps[i];
             if ((grp.name == Grp1Name || grp.name == Grp2Name)&& grp.textFrames.length > 0) {
                text  = grp.textFrames[0];
                h = text.height;
                text.contents = text.contents+"\n"+k;
                H = text.height;
                text.translate(0,H-h);
                k++;
             }
     }
  }
if (app.documents.length) main();

 

René

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

Copy link to clipboard

Copied

Merci à vous pour vos réponses.

@rcraighead This script is useful bur unfortunately it only count the groups and does not add number to them..

@renél80416020  Merci pour cette solution mais lorsque je lance le script voilà ce que j'obtiens...

polotrobo_0-1664175871400.png

 J'effectue certainement mal votre script.

Encore merci,

PM

 

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

Copy link to clipboard

Copied

LATEST

EDIT: Merci beaucoup @renél80416020 il y avait juste une coquille le nom du layer n'est pas VEY mais VEI, une fois changé tout fonctionne parfaitement, encore merci c'est parfait !! 

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