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

Script not hiding a <Group> inside a Layer, Unless <Group> is manually edited.

New Here ,
May 15, 2021 May 15, 2021

Copy link to clipboard

Copied

I have searched and have found some scripts that I retrofited for my needs. But here’s the interesting problem I’m having. I’m trying to hide the native created group named “<Group>” inside the Layer “guides/crops”. I have used the script bellow (that I doctored up), but it only works if the groupitems where manually edited in the Layers palette. That group name was automatically created by illustrator, and I assume the bracket “< >” are affecting how the script works. If I change the <Group> name in the layer palette to Group (or any other name), then the script works.  How can I make this work on native <Group> names? Working on ILL CS6 and Win10Pro.

FYI, there are only two <Paths> in the layer <Group>. I could try to hide the last 2 index paths inside the <Group>. But on some files this layers has more objects.

Thanks for your help.

 

Kbrenner_0-1621138757970.png

 

var docRef = app.activeDocument; 

var layers = docRef.layers; 

var myLayer = layers["guides/crops"]; //this defines the layer that you want to get the selection from 

//docRef.selection = null; //ensure there is nothing in the document selected already. this way you only get the selection you want. 

for(var a=0;a<docRef.groupItems.length;a++){

     if (docRef.groupItems[a].name == "<Group>"){

    //docRef.groupItems[a].selected = true;     

     docRef.groupItems[a].hidden= true; 

    }

}

TOPICS
Scripting

Views

544

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 2 Correct answers

Guide , May 15, 2021 May 15, 2021

<Group> means not having a name (an empty string). So you can do this

 

if (docRef.groupItems[a].name == ""){
    docRef.groupItems[a].hidden= true;
}

 

 

Votes

Translate

Translate
Community Expert , May 15, 2021 May 15, 2021

In adding to the @femkeblanco said, since groups does not have name, it will hide all groups without name in side the layer, "guides/crops".

var docRef = app.activeDocument;
var layers = docRef.layers;
var myLayer = layers["guides/crops"];
for (var a = 0; a < docRef.groupItems.length; a++) {
    if (docRef.groupItems[a].name == "") {
        docRef.groupItems[a].hidden = true;
    }
}

 

Votes

Translate

Translate
Adobe
Guide ,
May 15, 2021 May 15, 2021

Copy link to clipboard

Copied

<Group> means not having a name (an empty string). So you can do this

 

if (docRef.groupItems[a].name == ""){
    docRef.groupItems[a].hidden= true;
}

 

 

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 ,
May 15, 2021 May 15, 2021

Copy link to clipboard

Copied

In adding to the @femkeblanco said, since groups does not have name, it will hide all groups without name in side the layer, "guides/crops".

var docRef = app.activeDocument;
var layers = docRef.layers;
var myLayer = layers["guides/crops"];
for (var a = 0; a < docRef.groupItems.length; a++) {
    if (docRef.groupItems[a].name == "") {
        docRef.groupItems[a].hidden = true;
    }
}

 

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
New Here ,
May 16, 2021 May 16, 2021

Copy link to clipboard

Copied

LATEST

Thanks guys! That explains it.   I don't script enough to remember from one year to another, but I should have figure that out. For some reason I was transfix on selecting and hiding that particular group layer <Group>, which is actually an empty string without a real name, I see now. This new edit to the script, will globally hide all groups inside that layer. I'm lucky that there are only two groups in that layer, and I don't care (for now) if  it gets hidden. I did try a different script snippet and got it to work. Basically the same thing, but more direct. I like the top version one better incase I have a specific group to hide, in the future.

var doc = app.activeDocument;
var aLay = doc.layers['guides/crops'];
aLay.groupItems[0].hidden = true;



 

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