@Max Mugen
Give this a Try:
// Get the active document
var doc = app.activeDocument;
// Get an array of all existing layers
var allLayers = [];
for (var i = 0; i < doc.layers.length; i++) {
allLayers.push(doc.layers[i]);
}
// Get the active layer
var activeLayer = doc.activeLayer;
// Get the index of the active layer
var activeLayerIndex = -1;
for (var i = 0; i < allLayers.length; i++) {
if (allLayers[i] == activeLayer) {
activeLayerIndex = i;
break;
}
}
// Create a dialog window to ask the user to move the active layer up or down
var moveUpDownDialog = new Window("dialog", "Move Active Layer");
// Add a button group to the dialog window
var moveUpDownButtonGroup = moveUpDownDialog.add("group");
moveUpDownButtonGroup.orientation = "row";
// Add a "Move Up" button to the button group
var moveUpButton = moveUpDownButtonGroup.add("button", undefined, "Move Up");
moveUpButton.onClick = function() {
// Check if the active layer can be moved up
if (activeLayerIndex > 0) {
// Get the layer above the active layer
var layerAbove = allLayers[activeLayerIndex - 1];
// Move the active layer above the layer above it
activeLayer.move(layerAbove, ElementPlacement.PLACEBEFORE);
// Close the dialog window
moveUpDownDialog.close();
}
};
// Add a "Move Down" button to the button group
var moveDownButton = moveUpDownButtonGroup.add("button", undefined, "Move Down");
moveDownButton.onClick = function() {
// Check if the active layer can be moved down
if (activeLayerIndex < allLayers.length - 1) {
// Get the layer below the active layer
var layerBelow = allLayers[activeLayerIndex + 1];
// Move the active layer below the layer below it
activeLayer.move(layerBelow, ElementPlacement.PLACEAFTER);
// Close the dialog window
moveUpDownDialog.close();
}
};
// Show the dialog window
moveUpDownDialog.show();