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();
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.
Copy link to clipboard
Copied
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