Skip navigation
Currently Being Moderated

Arranging stacking order from top  to bottm

Aug 7, 2012 6:54 AM

Tags: #illustrator #javascript #learning_scripting

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();

 

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points