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

How to convert all layers into Group

New Here ,
Jan 05, 2017 Jan 05, 2017

Copy link to clipboard

Copied

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

Untitled-1 copy.JPG

Any help would be very, very appreciated!

Thank you

TOPICS
Scripting

Views

1.7K

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 Expert ,
Jan 05, 2017 Jan 05, 2017

Copy link to clipboard

Copied

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

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 ,
Jan 26, 2017 Jan 26, 2017

Copy link to clipboard

Copied

//if you're using Illustrator CS6+

function groupLayerContents()

{

    var docRef = app.activeDocument;

    var layers = docRef.layers;

    for(var a=0;a<layers.length;a++)

    {

        docRef.selection = null;

        var thisLay = layers;

        thisLay.hasSelectedArtwork = true;

        app.executeMenuCommand("group");

    }

}

groupLayerContents();

//if you're using a legacy version of Illustrator

//CS5 or earlier

function groupLayerContents()

{

    var docRef = app.activeDocument;

    var layers = docRef.layers;

    var tempLay = docRef.layers.add();

    tempLay.name = "temp";

    for(var a=1;a<layers.length;a++)

    {

        var thisLay = layers;

        var newGroup = tempLay.groupItems.add();

        newGroup.name = thisLay.name + " group";

        for(var b = thisLay.pageItems.length-1;b >-1; b--)

        {

            var thisItem = thisLay.pageItems;

            thisItem.moveToBeginning(newGroup);

        }

        newGroup.moveToBeginning(thisLay);

    }

    tempLay.remove();

}

groupLayerContents();

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 ,
May 29, 2022 May 29, 2022

Copy link to clipboard

Copied

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");
  }
}

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 ,
May 29, 2022 May 29, 2022

Copy link to clipboard

Copied

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?

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 ,
May 29, 2022 May 29, 2022

Copy link to clipboard

Copied

LATEST

Also realized I had extra if statement in there... but still get error when using as Action. 

 

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");
}

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