Ungroup objects back to their own layers - Illustrator

Community Beginner ,
Jan 12, 2022 Jan 12, 2022

Copy link to clipboard

Copied

Hi all, is there a way for Illustrator to ungroup elements back to their original layers they came from? (like InDesign does). Ticking 'remember layers' doesn't solve it.
Currently, say that I have
Box A in layer 1
Box B in layer 2
Box C in layer 3

I group them, the group moves to layer 1. I ungroup, the separate boxes STAY in layer 1 (when they should move back to 1, 2, 3)
Is there a script or plug-in that will enable this function? It's very time consuming having to open up Layer 1, and manually drag the objects back to where they came from - not to mention the risk of making mistakes.
Please help.
 
Thank you 

 

Screenshot 2022-01-12 at 16.20.07.png

TOPICS
Feature request , How to , Scripting , Third party plugins , Tools

Views

342

Likes

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

correct answers 1 Correct answer

Explorer , Jan 13, 2022 Jan 13, 2022
My solution requires repeated runs of the script, but it works. First save parent layers via object attribute, and restore on request. /* RememberLayers.jsx for Adobe Illustrator Description: Saving and restoring selected items to their original layers. The order within the layers is not restored Author: Sergey Osokin, email: hi@sergosokin.ru */ //@target illustrator app.preferences.setBooleanPreference('ShowExternalJSXWarning', false); // Fix drag and drop a .jsx file function main(...

Likes

Translate

Translate
Adobe Community Professional ,
Jan 12, 2022 Jan 12, 2022

Copy link to clipboard

Copied

As far as I know, Illustrator does not yet have this function. (Although InDesign does)

Can you do what you need to do with your multiple selected objects without grouping them?

Likes

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 Beginner ,
Jan 12, 2022 Jan 12, 2022

Copy link to clipboard

Copied

I can, workarounds as I've done thus far. Such feature would speed up the process, though.

Likes

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 Professional ,
Jan 12, 2022 Jan 12, 2022

Copy link to clipboard

Copied

Same, as per me as well it does not exist, unless if someone has workaround for that.

You can post your feature request at below link.

https://illustrator.uservoice.com/forums/333657-illustrator-desktop-feature-requests

 

Best regards

Likes

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 Beginner ,
Jan 12, 2022 Jan 12, 2022

Copy link to clipboard

Copied

Thank you, I'll submit.

Likes

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 ,
Jan 13, 2022 Jan 13, 2022

Copy link to clipboard

Copied

Hi danielem41796145, as our colleagues said there is no native feature. I don't know what your purpose is with this function, but yes, as you mentioned, it is possible to script it. Would you like me to try?

 

Best regards

Likes

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 Beginner ,
Jan 13, 2022 Jan 13, 2022

Copy link to clipboard

Copied

Hi Inacio, fantastic - if you can figure out a script it would be great! Thank you

Likes

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 ,
Jan 13, 2022 Jan 13, 2022

Copy link to clipboard

Copied

Okay Daniel, tomorrow we will have one. Until then !

Best regards

Likes

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 Beginner ,
Jan 13, 2022 Jan 13, 2022

Copy link to clipboard

Copied

cool, thank you!

Likes

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 ,
Jan 18, 2022 Jan 18, 2022

Copy link to clipboard

Copied

I loved the solution provided by our colleague Sergey Osokin. However I believe that sometimes all we need are quick actions, I don't know if that's the case here. As I said before, I couldn't verify what Danielem's demand really is, so I thought we'd walk together in search of a solution. So I suggest starting with a very simple script that just ungroups the objects and sends them each one to a layer, without worrying about keeping the original path of these objects. This script, for example, to be accessed quickly could be assigned a keyboard shortcut.
There is an interesting discussion about this here in the community:
https://community.adobe.com/t5/illustrator-discussions/tutorial-add-your-own-keyboard-shortcuts-to-y...

Now, if it's necessary for Daniel's demand to maintain the objects' original path, Sergey's idea would actually be a better option.

So Danielem, could you exemplify us with a real work? So we could work the script better.
Follow that simple script I mentioned just above.

/*
    Name-> UngroupAndMoveToLayer
    By-> Inacio Felipe
    Where-> https://community.adobe.com/t5/illustrator-discussions/ungroup-objects-back-to-their-own-layers-illustrator/m-p/12658180#M306036
    
    what are you doing->This script detects and ungroups objects into groups on a pre-selection.
    Names and moves each item in this undone group to a layer created and named for it.
    The name of objects and layers is created from the name of the group that was undone, and the name of each object.
    If the group, and or, the object does not have names, it will receive a generic name:
    "group 'i' _ iItem _ 'i'", where i is a numeric index
    note:
    This script works with the layers in the root, elements in the sub layers will be moved to the root
    and not to the source layer.

    Sugestions:
    look for AutoHotkey or
    https://community.adobe.com/t5/illustrator-discussions/tutorial-add-your-own-keyboard-shortcuts-to-your-jsx-scripts/m-p/3079389
*/
#target.Illustrator
#targetengine.ungroupAndMoveToLayer()
app.preferences.setBooleanPreference('ShowExternalJSXWarning', false); // Fix drag and drop a .jsx file

ungroupAndMoveToLayer()

function ungroupAndMoveToLayer(){
    
    doc=app.activeDocument
    layers=doc.layers
    sel=doc.selection
    groups=doc.groupItems

    try{
        if (app.documents.length<1){
            alert('Open document for work')
            return
        }
        else{
            // Verify if there is one selection
            if (sel.length<1){
                alert('No items selected. Select something to continue')
                return;
            }else{
                // Verify if there is groups in the selection
                j=0
                idGroup=0
                for (ii=0; ii<sel.length; ii++){
                    if (sel[ii].typename=="GroupItem"){
                        j++
                        idGroup+=1
                        //alert('Work with the group,' + idGroup + '\nwith a name: ' + groups[i].name + '\nwhere exists ' + sel[i].pageItems.length + ' items')
                        ungroupAndMakeLayer(sel[ii],idGroup)
                    }
                }

                if(j==0){
                    alert('Nothing for do. No groups in the selection')
                    return;
                }
            }
        }
    }
    catch(erro){
        alert ("The script don't run because:\n" + erro)
    }
}

function ungroupAndMakeLayer(group,idGroup){
    idItem=0
    for(i=group.pageItems.length-1; i>=0; i--){
        idItem=i+1
        // Rules for naming layers
            strGroupName=group.name
            if(strGroupName=='null' || strGroupName==''){
                strGroupName='group ' + idGroup
            }else{
                strGroupName=group.name
            }
            strItemName=group.pageItems[i].name
            if(strItemName=='null' || strItemName==''){
                strItemName='item_'+ idItem
            }else{
                strItemName=group.pageItems[i].name
            }
        //
        strLayerName=strGroupName + '_' + strItemName

        level=doc.layers
        //make the layer
        newLayer=makeLayer(level,strLayerName)
        group.pageItems[i].move(newLayer,ElementPlacement.PLACEATBEGINNING)
       
        //moves the new layer to layer of group
        layerOfGroup=group.parent
        moveToLayer(newLayer, layerOfGroup.name)

        redraw()
    }
}

function makeLayer(level,strName){
    /* Essa funcao cria e retorna uma nova camada se ela nao existir no nivel indicado
        parametros:
        -> nivel:
            nivel onde sera criada a camada.
            Ex.:
            'app.activeDocument.layers' para o primeiro nivel
            'app.activeDocument.layers[index].layer' para outros niveis
        -> strNome:
            string com o nome que sera atribuido a nova layer
    */
    var newLayer
    try {
        newLayer = level.getByName(strName);
    } catch (e) {
        // no layer by that name, so make it
        newLayer = level.add()
        newLayer.name = strName;
    }
    return newLayer;
}

function moveToLayer(item, strName) {
    /*
    Essa função move o item, para a camada com o nome
    -> item:
        qualquer item do illustrator
    -> strName:
        string com o nome da camada para onde será movido o item
    */
    var level
    try {
      level = activeDocument.layers.getByName(strName)
      item.move(level, ElementPlacement.PLACEATBEGINNING)
    } catch (e) {}
  }
Best regards

Likes

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 Beginner ,
Jan 18, 2022 Jan 18, 2022

Copy link to clipboard

Copied

LATEST

Hi!
Both solutions work, in different ways and will serve different purposes. I'll use them both!
Thank you!

Likes

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 ,
Jan 13, 2022 Jan 13, 2022

Copy link to clipboard

Copied

My solution requires repeated runs of the script, but it works. First save parent layers via object attribute, and restore on request.

2022-01-14 11.03.15.gif

 

/*
  RememberLayers.jsx for Adobe Illustrator
  Description:
  Saving and restoring selected items to their original layers.
  The order within the layers is not restored
  Author: Sergey Osokin, email: hi@sergosokin.ru
*/

//@target illustrator
app.preferences.setBooleanPreference('ShowExternalJSXWarning', false); // Fix drag and drop a .jsx file

function main() {
  if (!documents.length) return;
  if (selection.length == 0 || selection.typename == 'TextRange') return;

  var doc = activeDocument,
      docSel = selection,
      keyPref = 'origLayer=';

  // DIALOG
  var dialog = new Window('dialog', 'Remember Layers');
      dialog.preferredSize.width = 146;
      dialog.orientation = 'column';
      dialog.alignChildren = ['fill', 'center'];

  var saveBtn = dialog.add('button', undefined, 'Save');
  var restoreBtn = dialog.add('button', undefined, 'Restore');
  var cancel = dialog.add('button', undefined, 'Cancel', {name: 'cancel'});

  var copyright = dialog.add('statictext', undefined, '\u00A9 Sergey Osokin');
      copyright.justify = 'center';
      copyright.enabled = false;

  saveBtn.onClick = save;
  restoreBtn.onClick = restore;
  cancel.onClick = dialog.close;

  function save() {
    for (var i = 0, len = selection.length; i < len; i++) {
      var currItem = selection[i];
      removeNote(currItem, keyPref);
      currItem.note += keyPref + currItem.layer.name + ';';
    }
    dialog.close();
  }

  function restore() {
    var regexp = new RegExp(keyPref + '(.+)', 'g')
    for (var i = selection.length - 1; i >= 0; i--) {
      var currItem = selection[i],
          layerName = '';
      if (currItem.note.match(keyPref) !== null) {
        layerName = currItem.note.split(';')[0].replace(regexp, '$1');
        moveToLayer(currItem, layerName);
      }
      removeNote(currItem, keyPref);
    }
    dialog.close();
  }

  dialog.center();
  dialog.show();
}

// Remove keyword from Note in Attributes panel
function removeNote(item, key) {
  var regexp = new RegExp(key + '(.+);', 'g');
  item.note = item.note.replace(regexp, '');
}

// Move selected item to original Layer by name
function moveToLayer(item, name) {
  var origLayer;
  try {
    origLayer = activeDocument.layers.getByName(name);
    item.move(origLayer, ElementPlacement.PLACEATBEGINNING);
  } catch (e) {}
}

try {
  main()
} catch (e) {}

Likes

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 Beginner ,
Jan 13, 2022 Jan 13, 2022

Copy link to clipboard

Copied

Thank you so much, I'll give it a try!

Likes

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 Beginner ,
Jan 13, 2022 Jan 13, 2022

Copy link to clipboard

Copied

It works. thank you.

Likes

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