Quantcast
Channel: Adobe Community: Message List
Viewing all articles
Browse latest Browse all 135144

Re: Re: Space centres

$
0
0

try this Steve, hope I understood correctly...select your squares before running.

 

#target Illustrator

// script.name = distributeObjectsByTheirCenters.jsx;
// script.description = spaces out objects the supplied distance (by their centers);
// script.requirement = select 2 or more objects before running;
// script.parent = CarlosCanto // 10/05/14;
// script.elegant = false;


// https://forums.adobe.com/thread/1591527


// Note: the bottom most object will be used as the "Key" object, all others will align to it


function main () {
      try {var idoc = app.activeDocument;}    catch (e) {alert ('open a document and try again'); return };    var sel = idoc.selection;    var selcount = sel.length;      if (selcount>1) {        var title = 'Distribute Objects by their centers';        var a = prompt ('Distance X in points', 5, title);        if (a==null) return;        else a=Number(a);        var b = prompt ('Distance Y in points', 0, title);        if (b==null) return;        else b=Number(b);              var pgItemBottom = sel[selcount-1];        var baseCenter = getCtrPoint(pgItemBottom, false);        var cx = baseCenter[0];        var cy = baseCenter[1];              for (var i=selcount-2; i>=0 ; i--) {            var pgItem = sel[i];            cx = cx+a;            cy = cy+b;            getCtrPoint(pgItem, true, cx, cy);        }    }    else {alert ('select two or more objects and try again'); return }
} // end main


// get center point of supplied object, returns a point (x,y)
// or space out object the supplied distance from the center (if distribute is true)
function getCtrPoint(object, distribute, cx, cy) {
    var bounds = object.geometricBounds;    //var bounds = path.geometricBounds; // left, top, right, bottom    var halfwidth = (bounds[2]-bounds[0])/2;    var halfheight = (bounds[1]-bounds[3])/2;    var x = bounds[0]+halfwidth; // left + width/2    var y = bounds[3]+halfheight; // bottom + height/2      if (!distribute) {        return pathCtrPoint = Array(x,y); // [50, 50] for example    }    // if distribute is true, re position the object, otherwise return the center point    object.position = [cx-halfwidth, cy+halfheight];    return
}


main ();

Viewing all articles
Browse latest Browse all 135144

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>