0

This is ideal for the creation of isometric graphics. You can replicate an isometric tile symbol with a graphic in it, like a house or a tree, multiple times, then run the script to re-stack all selected objects (symbols). This is necessary so their overlaps are correct, matching the faux perspective of an isometric game.

I'm sure I used one years ago to create an isometric forest but I can no longer find the script in my files, nor online.

I'm considering writing it myself but if anyone can remember where the script is that would be a lot easier! 🙂

Thank you.

ps- I guess I'd have to use Math.abs to write such a script as the Y-axis in Illustrator is inverted. No idea yet how to get an objects z-index reordered though.

  • There is no z - index in illustrator. Only file order. So you just use the move command to move it before or after another object in the hierarchy. This bodes bad for any group or layer. – joojaa Nov 11 at 14:35
  • So there's no way to refer to depth/z-index/stack order, whatever, in AI js? I'm off to look through the books. If I get a simple script together I'll post here again. – runninghead Nov 11 at 14:48
  • I didnt say that, i said there is no z-index. Order is strictly a feature of where in document something is. So if its before another object in the document tree then its drawn first. This means that you can only do this if your document has no layers or groups since objects get drawn in the document order to sort youd have to break these features or ignore them. The object.move command is there to facilitate this. (Move does not move objects in space but in hierarchy, translate moves objects in space) – joojaa Nov 11 at 15:10
  • Also there is no way to find the furthest point of a object in some direction since there is no evaluation functions for beziers so youd need to euther write your own slow bezier functions, rotate scene or use some other proxy. If you can overcome the limitations with rules of the object order and use a proxy for the sorting distance its pretty trivial to write a O( N log N) loop to do this. I cant just decide implementation details to you. – joojaa Nov 11 at 15:18
  • Thanks, looking forward to this one as I know it can be done and has been done before. The object.move tip is great, thanks @joojaa, it might be just the command I need. By z-index I was just trying to refer to stacking order / visual depth in a way that would be easily understood by a wide range of potential readers. I think the script will be very short for this one 🙂 – runninghead Nov 11 at 18:49
0

Here is a naive implementation that sorts by each object in selection. It ignores groups and layers. It actually sorts by the furthest point along angle

enter image description here

#target Illustrator

{
    var sel = app.selection;    
    generateComparasion(sel);
    sel.sort(sortByComp);
    stack(sel);
}

//====== Support funcs ==========

function sortByComp(a,b){
     return (a.comp > b.comp) ? -1 : 1    
}

// Rotate object to ange to find its furthest point along axis. then rotate it back
function generateComparasion(sel){
    var angle= 30.0;
    var rotation = app.getRotationMatrix(angle);
    var counter = app.getRotationMatrix(-angle);

    
     var len = sel.length;
    for (var i=0;i<len;i++){
        var item = sel[i];
        item.transform(rotation, true, false, false, false, 1.0, Transformation.DOCUMENTORIGIN );
        item.comp=item.position[1]+ item.height;
        item.transform(counter, true, false, false, false, 1.0, Transformation.DOCUMENTORIGIN );
   }
}

function stack(sel){
     var layer = app.activeDocument.layers[0];
    var len = sel.length;
    for (var i=0;i<len;i++){
        var item = sel[i];
        item.move(layer, ElementPlacement.PLACEATBEGINNING  )
    }   
 }
| improve this answer | |
  • Nice use of maths @joojaa ! I have a screen grab of the result on a simple test file (8 tree symbols in a layer) that shows how the last object is not ordered correctly by this script, though the rest of the objects are perfectly arranged. If only I could post an image here 😏 – runninghead Nov 12 at 11:10
  • @runninghead it may be that the rotating trick does not really work with symbols well, but i might have made a bug when i made the cleanup of the code too. I must test – joojaa Nov 12 at 14:10
  • (@runninghead, you can upload your image on imgur by clicking "New post" and then link to it in your comment like described in the "help" link below.) – Wolff Nov 12 at 17:19
  • 1
    @Wolff yes but you can just edit or make an answer use the link image copy the code and cancel the edit. Does the same thing dont have to leave the webpage. So you can decide mid comment to add a image. – joojaa Nov 12 at 17:33
  • 1
    Loving getting back in to scripting and I love that stack function @joojaa. Thanks for the advice @Wolff, I'll try the adjusted method later here just to see how it works. btw: I'm trying something today that I like (though it may not be the best way to achieve the required result); Giving each object a score to indicate how far forward they should be in iso perspective. score = Math.round(sel[i].left + Math.abs(sel[i].top)); – runninghead Nov 13 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.