Skip to main content
dublove
Legend
Apr 23, 2026 5:43 PM UTC
Answered

How to move a layer to the top and move an object to a specific layer?

How do I move a layer to the top and move an object to a specific layer?
For example, I have three layers, and I want the final order from top to bottom to be:
A1
A2
A3.
I’d like to know how to use code to move A1 to the top.
Additionally, I want to move the selected object to A2.

I found this, but I don’t seem to understand it:
https://community.adobe.com/questions-671/script-for-object-styles-being-applied-to-specific-layer-880528

Thank you.

    rob day
    rob dayCorrect answer
    Community Expert
    Apr 23, 2026 7:01 PM UTC

    This moves the layer named A1 to the top:

     

    //a layer named A1
    var a1 = app.activeDocument.layers.itemByName("A1")
    //moves A1 to the top
    a1.move(LocationOptions.AT_BEGINNING)

     

    Before and after

     

     

    The layer move method:

     

    You can also move layers via their index —top index is 0. This moves the bottom layer to 1 below the top layer. BEFORE and AFTER use the 2nd parameter, which is a layer

    var l = app.activeDocument.layers
    //l[l.length-1] is the bottom layer, l[0] is the top layer,
    //moves the bottom layer to 1 below the top layer
    l[l.length-1].move(LocationOptions.BEFORE, l[1])

     

    8 replies

    dublove
    dubloveAuthor
    Legend
    May 1, 2026 8:23 AM UTC

    Hi rob day.

    Can I set the position while creating the layer? 
    In other words, can I combine “myLayer.move(LocationOptions.AT_END);” with the following line:
     var myLayer = app.activeDocument.layers.add({ name: “A1”, layerColor: [18, 60, 29] });
    Like this:

    var myLayer = app.activeDocument.layers.add({ name:“A1”, layerColor:[18, 60, 29], position: LocationOptions.AT_END});

     

    Translate
    rob day
    Community Expert
    Community Expert
    May 1, 2026 11:55 AM UTC

    There is no position property and index is read only, so I think you have to use the move() method

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

    Translate
    dublove
    dubloveAuthor
    Legend
    Apr 24, 2026 6:40 AM UTC

    How to use 6-bit RGB color values.
    This usage is acceptable:

    var myLayer = app.activeDocument.layers.add({ name: "A", layerColor: UIColors.magenta });

    This 6-bit format is not supported:

     var myLayer = app.activeDocument.layers.add({ name: "A", layerColor: UIColors.#ef8910 });

     

    sorry, I know:

    var myLayer = app.activeDocument.layers.add({ name: "A", layerColor: [239, 137, 16] });

     

    Translate
    rob day
    Community Expert
    Community Expert
    Apr 23, 2026 10:27 PM UTC

    Additionally, I want to move the selected object

     

    Missed your 2nd question—this moves a selection in the bottom layer to the top layer:

    var d = app.activeDocument;
    var l = app.activeDocument.layers
    var s = d.selection[0]
    s.move(l[0])

    Before after:

     

    Translate
    rob day
    Community Expert
    rob dayCommunity ExpertCorrect answer
    Community Expert
    Apr 23, 2026 7:01 PM UTC

    This moves the layer named A1 to the top:

     

    //a layer named A1
    var a1 = app.activeDocument.layers.itemByName("A1")
    //moves A1 to the top
    a1.move(LocationOptions.AT_BEGINNING)

     

    Before and after

     

     

    The layer move method:

     

    You can also move layers via their index —top index is 0. This moves the bottom layer to 1 below the top layer. BEFORE and AFTER use the 2nd parameter, which is a layer

    var l = app.activeDocument.layers
    //l[l.length-1] is the bottom layer, l[0] is the top layer,
    //moves the bottom layer to 1 below the top layer
    l[l.length-1].move(LocationOptions.BEFORE, l[1])

     

    Translate
    dublove
    dubloveAuthor
    Legend
    Apr 24, 2026 2:53 AM UTC

    Thank you very much

    I just realized that I can also move it to Layer A.

    var myLayer = d.layers.itemByName(‘A’);
    s.itemLayer = myLayer;

     

    Translate
    kglad
    Community Expert
    Community Expert
    Apr 23, 2026 6:04 PM UTC

    you can drag and drop objects and layers.

    Translate
    leo.r
    Community Expert
    Community Expert
    Apr 23, 2026 6:12 PM UTC

    his question is about scripting the process.

    Translate