Skip to main content
dublove
Legend
October 24, 2025
Answered

What is the code to move the currently selected object up one layer?

  • October 24, 2025
  • 1 reply
  • 10066 views

For example:

I want sel[j] to be positioned above sel[j-1];

var doc = app.activeDocument;
var item = doc.selection;
sel = items;
for (var i = 0; i < sel.length; i++) {

};

 

Correct answer rob day

Hi rob day.

move()?
For example,
how do I use it? If possible, I'd like to get it done in one go.


how do I use it?

 


var d = app.activeDocument

//a selection on the bottom layer
var s = d.selection[0]

//this doesn’t do anything because s 
//is the only object on the item Layer named "Gray"
s.bringForward()

//make a new layer
var ns = makeLayer(d, "New Gray Layer");

//moves the selected page item to New Gray Layer 
// note that the parameter has to be a reference to an item Layer
s.move(ns)

/**
* Makes a new named Layer 
* @ param the document to add the layer 
* @ param layer name 
* @ return the new layer 
*/

function makeLayer(d, n){
    if (d.layers.itemByName(n).isValid) {
        return d.layers.itemByName(n);
    } else {
        return d.layers.add({name:n});
    }
}

 

 

1 reply

rob day
Community Expert
Community Expert
October 24, 2025

Do you want to move a page item up in the containing layer’s stacking order?

 

Here there are 3 page items in Layer 1 (there’s only 1 Document Layer). To move the selected item up 1 place in Layer 1’s stacking order (there is also s.bringToFront(), s.sendToBack(), s.sendBackward()):

var s = app.activeDocument.selection[0]
s.bringForward()

 

 

dublove
dubloveAuthor
Legend
October 25, 2025

Thanks, that's exactly what I meant.
Successfully completed.

 

There's no such thing as "bringToBottom"?

(Place it on the bottom layer)