Script for Batch-Moving Layers More Easily?

New Here ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

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.

TOPICS
Feature request , Scripting

Views

109

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

Adobe Community Professional , Apr 26, 2022 Apr 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...

Likes

Translate

Translate
Adobe Community Professional ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

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.

 

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
New Here ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

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!

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 ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

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

 

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
New Here ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

Thank you for your reply! I know what you mean about sublayers, my previous struggles with them were why I avoided using them but now they do seem to be meeting my needs. 

 

I did try the script you suggested but unfortunately it just seems to take whatever layers I select and merge them together? The number entered doesn't seem to affect this either. 

 

To be honest, even if it did work, I realised that using that would also require me knowing the exact number of spots to move! My dream is that illustrator either allows an increase in the click-drag scroll speed, or some option to paste layers underneath/above a given selected layer. 

 

Thank you again for trying! 

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 ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

I also tried out Mark's script and found that it actually works pretty well.

 

Perhaps your conception about what "layers" versus "objects" mean is different from Illustrator's idea. Can you provide a sample Illustrator file, so one may have a look at it?

 

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 ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

LATEST

Yes, I understand. However the solution already exists, and @Kurt Gold already alluded to it.

 


@user2712901 wrote:

or some option to paste layers underneath/above a given selected layer. 

 

Illustrator already does this natively and I reckon I do it hundreds of times a day: Paste In Front and Paste In Back. These commands will past the clipboard contents in the same position x,y but directly in front/back of *the selection* in z order. So: make a selection, ctrl/cmd-X, make another selection, ctrl/cmd-F (or B) and this does exactly what you are asking for, with no messing with the Layers Panel at all.

 

Still, the script was fun to write. 🙂

- Mark

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