Skip to main content
Participating Frequently
January 12, 2016
Answered

How to convert all groups to layers

  • January 12, 2016
  • 1 reply
  • 13521 views

Hello all,

I have a gigantic file with multiple groups containing each mutiple subgroups wich contain... you guessed it, many other groups.

I need to convert every single group of this file to a layer, and respect the same order (groups, subgroups and so on) to make this drawing usable and editable.

Unfortunately, I have zero skills in JS or programming.

Has anyone faced the same issue? I'm looking for a script that would create the layers, name them and move the content automatically to the appropriate layer. It would be just waaaayyy to long to do it manually because the file contains over 20,000 shapes (plus I have several other files that I need to convert the same way).

Any help would be very, very appreciated!

Thank you

This topic has been closed for replies.
Correct answer Silly-V

Ok, give this a try. It works best when you start out with only 1 layer and that layer has only groups inside the top-level.

#target illustrator-19

function test(){

    var doc = app.activeDocument;

    var originalLayer = doc.layers[0];

    var newLayer, thisGroup, thisContent;

    for(var i=originalLayer.groupItems.length - 1; i > -1; i--){

        thisGroup = originalLayer.groupItems[i];

        newLayer = doc.layers.add();

        newLayer.name = thisGroup.name;

        for(var j=thisGroup.pageItems.length - 1; j > -1; j--){

            thisContent = thisGroup.pageItems[j];

            thisContent.move(newLayer, ElementPlacement.PLACEATBEGINNING);

        };

    };

    app.redraw();

    if(originalLayer.pageItems.length == 0){

        originalLayer.remove();

    }

}

test();

1 reply

Silly-V
Brainiac
January 12, 2016

They got a nice feature for this kind of thing inside the fly-out menu of the Layers panel, it's called "Release to Layers: Sequence". Highlight your layer and use this command to turn all your items in this layer into their own layers. Then, if you select all, you can do a single ungroup to get rid of the top-level groups in each of your layers, so what were your groups are now your layers!

Participating Frequently
January 12, 2016

Hello Silly-V

Unfortunately, this does not seem to work. It moves selected groups under new layers, but keeps the groups intact.

What I am looking for is a way to create a layer with the same name as the group and move the content from the group to this new layer.

But thank you for your suggestion

Participating Frequently
January 12, 2016

Ok, give this a try. It works best when you start out with only 1 layer and that layer has only groups inside the top-level.

#target illustrator-19

function test(){

    var doc = app.activeDocument;

    var originalLayer = doc.layers[0];

    var newLayer, thisGroup, thisContent;

    for(var i=originalLayer.groupItems.length - 1; i > -1; i--){

        thisGroup = originalLayer.groupItems[i];

        newLayer = doc.layers.add();

        newLayer.name = thisGroup.name;

        for(var j=thisGroup.pageItems.length - 1; j > -1; j--){

            thisContent = thisGroup.pageItems[j];

            thisContent.move(newLayer, ElementPlacement.PLACEATBEGINNING);

        };

    };

    app.redraw();

    if(originalLayer.pageItems.length == 0){

        originalLayer.remove();

    }

}

test();

Hummmm... very interesting! You are definitely onto something here!!

It works, but only for first level groups... My file goes down to 4 levels.... so close!!!!!

I am currently on CS6, do you believe it would make any difference if I was on CC instead?