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

Arranging stacking order from top to bottm

Explorer ,
Aug 07, 2012 Aug 07, 2012

Copy link to clipboard

Copied

I solved my original query, and have removed the original defective script from this post. The script below takes any set of selected objects and rearranges their stacking order so that the (vertically) topmost object is at the back of the stack, the vertically lowest at the front (and similarly for all intervening objects).

It should now replicate the action of JET_StackTopToBottom.jsx, which is apparently no longer available. I hope this may help anyone who, like me, would gladly have paid to find it!

David Entwistle

var thisDoc = activeDocument;

// get selected objects

var selObj = thisDoc.selection;

// count the selected objects

var selObjCount = selObj.length;

// sort selected objects by their height from the page origin

var byProperty = function(prop) {

    return function(a,b) {

        if (typeof a[prop] == "number") {

            return (a[prop] - b[prop]);

        } else {

            return ((a[prop] < b[prop]) ? -1 : ((a[prop] > b[prop]) ? 1 : 0));

        }

    };

};

var symbolsSorted = selObj.sort(byProperty("top"));

// for each object in turn in the ordered selection, BringToFront

for(i = selObjCount; i >0; i--){

          var currObj = symbolsSorted[i-1];

          currObj.zOrder(ZOrderMethod.BRINGTOFRONT);

}

redraw();

TOPICS
Scripting

Views

2.0K

Translate

Translate

Report

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
Adobe
Explorer ,
Oct 21, 2015 Oct 21, 2015

Copy link to clipboard

Copied

Awesome, thank you! Just what I was looking for, sorted my trees (symbols) back to front. I have plenty of use for this for perspective illustrations using symbols or repeated objects.

Votes

Translate

Translate

Report

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
Participant ,
Dec 06, 2016 Dec 06, 2016

Copy link to clipboard

Copied

LATEST

I know this post is over 4 years old now but I just wanted to say thank you.  I've been working on a perspective script for some time now trying to get it all to sort by Zorder and this solved my problems in a lot easier fasion.  I don't know if you ever get on these forums or not anymore but thank you very much @David_Entwistle

Votes

Translate

Translate

Report

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