how to collapse a layer by javascript?

Engaged ,
Jul 29, 2022 Jul 29, 2022

Copy link to clipboard

Copied

Hello,

 

I looking for the commands in javscript to collapse/fold and extend/unfold a layer and/or a group in Illustrator. 

 

Thanks for any hints or tips in advance,

jens

TOPICS
Scripting

Views

104

Likes

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

Advisor , Jul 29, 2022 Jul 29, 2022

As @Charu Rajput said, collapsing layers is almost certainly not possible.  I was however able to expand all layers with items in them.  As an action, record the command "Locate object" from the layers panel menu.  In the script, iterate the top level layers and call the action each time. 

 

var layers = app.activeDocument.layers;
for (var i = 0; i < layers.length; i++) {
    app.selection = null;
    layers[i].hasSelectedArtwork = true;
    app.doScript("Action 1", "Set 1");
}

 

Likes

Translate

Translate
Adobe Employee ,
Jul 29, 2022 Jul 29, 2022

Copy link to clipboard

Copied

Hello @Parts4Arts,

 

Thanks for reaching out. I would request you try the suggestions shared in this community post (https://community.adobe.com/t5/photoshop-ecosystem-discussions/expand-collapse-a-group-via-javascrip...) and check if it helps.

 

Looking forward to hearing from you.

 

Thanks,

Anubhav

Likes

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
Engaged ,
Jul 29, 2022 Jul 29, 2022

Copy link to clipboard

Copied

Hello and thank you for the link. However, the discussion is 7 years and not all downloads work anymore. Also, it is about photoshop there. I am looking for a solution for Illustrator.
To my knowledge there is no command like "stringIDToTypeID" in the javascript for Illustrator.

Likes

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
Adobe Community Professional ,
Jul 29, 2022 Jul 29, 2022

Copy link to clipboard

Copied

Hi @Parts4Arts 

As far as I know, not possible with scripting.

Below is the link that may help too

https://community.adobe.com/t5/illustrator-discussions/script-to-expand-and-or-collapse-layers/td-p/...

 

Best regards

Likes

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
Advisor ,
Jul 29, 2022 Jul 29, 2022

Copy link to clipboard

Copied

As @Charu Rajput said, collapsing layers is almost certainly not possible.  I was however able to expand all layers with items in them.  As an action, record the command "Locate object" from the layers panel menu.  In the script, iterate the top level layers and call the action each time. 

 

var layers = app.activeDocument.layers;
for (var i = 0; i < layers.length; i++) {
    app.selection = null;
    layers[i].hasSelectedArtwork = true;
    app.doScript("Action 1", "Set 1");
}

 

Likes

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
Engaged ,
Jul 30, 2022 Jul 30, 2022

Copy link to clipboard

Copied

LATEST

Hello and thanks for this information and idea using an action.

 

Have a good weekend.

– j.

Likes

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