Skip to main content
dublove
Legend
September 2, 2025
Answered

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

  • September 2, 2025
  • 2 replies
  • 202 views

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

 

Correct answer m1b

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());

})();

2 replies

Fred.L
Inspiring
September 2, 2025

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

dublove
dubloveAuthor
Legend
September 2, 2025

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.

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
September 2, 2025

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());

})();
dublove
dubloveAuthor
Legend
September 2, 2025

Thank you very much.
Learned another trick.