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 14, 2016

This is a good & very elegant way to do it! I'm curious what kind of workflow this is a part of that you have to have layers instead of groups specifically?


First thing, for a technical reason that I can't explain, using layers accelerates significantly the CPU processing required to manipulate huge files... in a crazy way... I don't know if it's only my PC that behaves like this or if its the same for everyone, but without layers, my PC would have to re-render the drawing every time I clicked on something.... Even on stuff that has nothing to do with the drawing itself; like browsing through menus and toolbars... Insane... My PC would take a minute or two to render the file everysingle time... crazy... With the groups gone, it's smooth sailing. Rendering the document would require 5 seconds instead of a minute. I would be curious why this is happening. Also, performance is significantly better if I move a lot of elements around within that drawing.

Second, using layers allows to select elements from differents parts/groups (now layers) and align them together quickly and efficiently rather than having to go inside each nested group, select the desired item, align it, go back a few levels up, then down again, then up again and so on... (or shift selecting items from different groups within the layers toolbar)

The only flaw so far with the above code is that everything has to be contained within a group, if some groups already live within a layer, the nested groups won't be processed.

As I mentioned earlier, I'm working on drawings containing over 20,000 items each... These drawings are initially handed over in SVG format, then I need to clean them up and re-arrange them in Illustrator. Unfortunately, groups in SVGs do not translate as "layers" in Illustrator. So my challenge was to convert every group to layers by respecting and keeping the layer structure and names.

In the end, saving a few minutes here and there while aligning stuff (and waiting for rendering) translates in at least 2 hours saved daily, 10 hours saved every week and a whole week saved after a month..! It was totally worth it!