Skip to main content
dublove
Legend
Sep 2, 2025 4:30 AM UTC
Answered

How to place a newly created layer at the bottom of all layers?

I created a new “guides” layer and want to place it at the bottom.
How do I do that?

This catch seems incorrect; it should check whether this layer already exists.

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Layers.html

    var myLayer = myDocument.layers.item("guides");
    try {
        myLayerName = myLayer.name;
    }
    catch (myError) {
        var myLayer = myDocument.layers.add({ name: "guides" });
    }

 

m1b
m1bCorrect answer
Community Expert
Sep 2, 2025 4:41 AM UTC

Use the move method of Layer:

 

(function () {

    var myDocument = app.activeDocument;

    var myLayer = myDocument.layers.item("guides");
    try {
        myLayerName = myLayer.name;
    }
    catch (myError) {
        var myLayer = myDocument.layers.add({ name: "guides" });
    }

    // move to bottom layer
    myLayer.move(LocationOptions.AFTER, myDocument.layers.lastItem());

})();

4 replies

Fred.L
Inspiring
Sep 2, 2025 6:30 AM UTC

Hey there,

Since you’re using a script anyway, you could expand its functionality by creating the Guides Layer and setting other options in the meantime. For instance, you could map a whole set of layers for new documents, ensuring consistency in the appearance of your documents.

Personally, I follow this approach:
- Create an array containing [Layer name, Layer color]
- Create all layers based on the array
- Sort the layers according to the array

Translate
dublove
dubloveAuthor
Legend
Sep 2, 2025 6:59 AM UTC

You're way too fancy.
I'm just here to hold the reference lines(guides).
I don't recommend using complex layers.
Because I think complex layer operations carry risks.

Translate
m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
Sep 2, 2025 4:41 AM UTC

Use the move method of Layer:

 

(function () {

    var myDocument = app.activeDocument;

    var myLayer = myDocument.layers.item("guides");
    try {
        myLayerName = myLayer.name;
    }
    catch (myError) {
        var myLayer = myDocument.layers.add({ name: "guides" });
    }

    // move to bottom layer
    myLayer.move(LocationOptions.AFTER, myDocument.layers.lastItem());

})();
Translate
dublove
dubloveAuthor
Legend
Sep 2, 2025 5:54 AM UTC

Thank you very much.
Learned another trick.

Translate