Skip to content

Instantly share code, notes, and snippets.

@sonburn
Created May 31, 2018 20:04
Show Gist options
  • Select an option

  • Save sonburn/d15c8308af50df194c30ea9523e587bc to your computer and use it in GitHub Desktop.

Select an option

Save sonburn/d15c8308af50df194c30ea9523e587bc to your computer and use it in GitHub Desktop.
function sortLayerList(layers,output,reverse) {
var layers = (reverse && reverse == 1) ? layers.reverseObjectEnumerator().allObjects() : layers,
loop = layers.objectEnumerator(),
layer;
while (layer = loop.nextObject()) {
var output = (output) ? output : layer.parentGroup();
layer.moveToLayer_beforeLayer(output,nil);
}
}
// Sort selected layers, don't change output location, reverse order
sortLayerList(context.selection,nil,1);
// Sort selected layers, change output location, respect order
sortLayerList(context.selection,context.document.currentPage(),0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment