Skip to main content
Participating Frequently
Jan 5, 2017 9:22 AM UTC
Question

How to convert all layers into Group

Hi all,

I have a file with multiple layers containing multiple items.

i want each layers inside items convert into group but remain in layer how can i do this with scripts. i have used LayerToGroup.jsx script but with this just 1 top layer convert other remain the same. I need to convert every single layer into group

Any help would be very, very appreciated!

Thank you

This topic is closed to new replies. Start a new post to keep the conversation going.

5 replies

Participating Frequently
May 29, 2022 8:18 PM UTC

The above didn't work for me, so I hacked this together from a few different references. I'm SURE it needs variables etc to clean up, as I'm only a hack coder, but this works for me: 

 

if (app.documents.length > 0) {
  if (app.activeDocument.layers.length > 1) {
    for (var i = 0; i < app.activeDocument.layers.length; i++) //loop through all TOP LEVEL layers
    {
		app.activeDocument.layers[i].hasSelectedArtwork = true; //selects all in active layer
		app.executeMenuCommand('group'); //groups all selected
		app.activeDocument.selection = null; //deselect
    }
  } else {
    alert("The active document only has only 1 layer");
  }
}
Translate
Participating Frequently
May 29, 2022 11:11 PM UTC

Here's an interesting catch with this script... if I run it from the File->Scripts menu item... all is well. If I make an Action that runs that same menu item... I get an error dialoge, then another saying the "deselect" line  throws the error. Can anyone explain this?

Translate
Larry G. Schneider
Community Expert
Community Expert
Jan 5, 2017 10:59 AM UTC

Try over in the Illustrator Scripting Forum. Check on the Overview tab.

Translate