Skip to main content
Participant
April 26, 2022
Answered

Script for Batch-Moving Layers More Easily?

  • April 26, 2022
  • 1 reply
  • 1181 views

I often have to drag many layers at a time from the bottom of the layers panel to a specific place, usually near the top. For example: 

 

ORIGINAL

 

Layers 1-100

Layers 101-200

Layers 201 - 300

Layers 301 - 400

 

WHAT I NEED

 

Layers 1-100

Layers 301 - 400

Layers 101-200

Layers 201 - 300

 

Unfortunately this takes considerable time using just click and drag. This would be simple if Illustrator had layer folders, but it doesn't. Currently it means selecting a batch,then dragging them to the top of the panel, and waiting for it to slowly scroll past hundreds of layers. 

 

I have found a semi-workaround using paste remember layers, copying, deleting the originals and pasting the new ones as they default to the top, but sometimes I have to drag from the bottom to a more specific place so this doesn't help too much. 

 

Is there any kind of script I can use to take a selected batch of layers and move them up x number of positions on the layers panel? Or at least a 'send to top' option? 

 

I am not good at scripting at all so would very much appreciate any advice! 

Thank you in advance! I'm using Illustrator CC 26.2.1.

This topic has been closed for replies.
Correct answer Kurt Gold

There are sublayers available in the Layers palette, so you may consider to use them in order to structure your arrangement.

 

Assuming you are instead talking about single objects in one main layer, there are several ways to quickly move them. For example, you can select them and then just use the Object menu > Arrange > Bring to Front command to move them to the top of the stack.

 

Or you can select and cut them, select any object that is supposed to be the "insertion point", then use the Edit menu > Paste in Front command to move them above the insertion point object.

 

1 reply

Kurt Gold
Community Expert
Kurt GoldCommunity ExpertCorrect answer
Community Expert
April 26, 2022

There are sublayers available in the Layers palette, so you may consider to use them in order to structure your arrangement.

 

Assuming you are instead talking about single objects in one main layer, there are several ways to quickly move them. For example, you can select them and then just use the Object menu > Arrange > Bring to Front command to move them to the top of the stack.

 

Or you can select and cut them, select any object that is supposed to be the "insertion point", then use the Edit menu > Paste in Front command to move them above the insertion point object.

 

Participant
April 26, 2022

I have explored sublayers before and found them to be unsuitable as there was issues with the way they handled objects vs layers, however your reply made me check them out again and realise they actually do work like the folder system in photoshop. Must have been a weird blind spot on my part. This will save me hundreds of hours in the future. Thank you for your help!

m1b
Community Expert
Community Expert
April 26, 2022

Hi @user2712901,

Sounds like sublayers might be best for your situation but personally I never use them because of annoying inconsistencies in the way they behave. Anyway, I was intrigued by the scripting challenge and I've had a go at making a script that does what you want I think. Would you mind giving it a try? You first select the items, then run script, and enter a number for how far you want to move them in Z order—positive means forwards, negative means backwards.

- Mark

 

/*
    Move Selected Items in Z Order
    for Adobe Illustrator 2022

    by m1b
    here: https://community.adobe.com/t5/illustrator-discussions/script-for-batch-moving-layers-more-easily/m-p/12905152

    Usage:
    - select page items (preferably that are contiguous in layer order — see note below)
    - when prompted by script, enter a number to move selected items in Z order;
      a positive number will move towards front, a negative number will move towards back

    Known Limitations:
    - script is designed to be used when selected items
      are contiguous in Z order, otherwise script will
      bunch them together, which might be confusing

*/

var doc = app.activeDocument,
    items = doc.selection,
    n;

if (n = Number(prompt('Move selection forward by N items, N =', '5'))) {
    moveItems(items, n);
}

function moveItems(items, n) {
    var masterItem = undefined,
        offset = n < 0 ? -1 : items.length - 1;
    for (var i = items.length - 1; i >= 0; i--) {
        masterItem = moveItem(items[i], n + offset, masterItem);
    }
}

function moveItem(itemToMove, n, referenceItem) {
    if (referenceItem != undefined) {
        itemToMove.move(referenceItem, ElementPlacement.PLACEBEFORE);
        return itemToMove;
    }
    else {
        var allItems = doc.pageItems;
        for (var i = allItems.length - 1; i >= 0; i--) {
            if (
                i - n >= 0
                && i - n < allItems.length
                && allItems[i].uuid == itemToMove.uuid
            ) {
                itemToMove.move(allItems[i - n], ElementPlacement.PLACEBEFORE);
                return itemToMove;
            }
        }
    }
}