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
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");
}
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
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.
Copy link to clipboard
Copied
Hi @Parts4Arts
As far as I know, not possible with scripting.
Below is the link that may help too
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");
}
Copy link to clipboard
Copied
Hello and thanks for this information and idea using an action.
Have a good weekend.
– j.