Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Guide ,
Oct 24, 2025 Oct 24, 2025

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++) {

};

dublove_0-1761327459567.jpeg

 

TOPICS
Bug , Scripting
10.1K
Translate
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 3 Correct answers

Community Expert , Oct 24, 2025 Oct 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()

 

Screen Shot 32.png

 

Screen Shot 33.png

Translate
Community Expert , Oct 25, 2025 Oct 25, 2025

Hi @dublove this function can set the stacking order. I am using a left-then-top sorting function, but you can use any criteria for sorting.

- Mark

 

/**
 * @file Set Item Stacking Order.js
 * @author m1b
 * @version 2025-10-25
 */
function main() {

    var doc = app.activeDocument;
    var items = doc.selection;

    // must update `items` with new item references
    items = setItemStackingOrder(doc, items, sortByLeftTop);


};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoMode
...
Translate
Community Expert , Oct 25, 2025 Oct 25, 2025

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 
* 
...
Translate
Guide ,
Oct 25, 2025 Oct 25, 2025
LATEST

Alright then, I'll look into it when I have some free time.

Translate
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