Skip to content

Instantly share code, notes, and snippets.

@yasushisakai
Last active December 15, 2015 10:09
Show Gist options
  • Save yasushisakai/5244095 to your computer and use it in GitHub Desktop.
Save yasushisakai/5244095 to your computer and use it in GitHub Desktop.
script for illustrator connects two objects in a bezier curve (vertical)
/**
* Created with JetBrains WebStorm.
* Date: 12/05/02
* Time: 13:05
*/
sel = activeDocument.selection;
function getCenter(_obj){
var position = _obj.position;
position[0]=position[0]+_obj.width/2.0; //x
position[1]=position[1]-_obj.height/2.0; //y
return position;
}
function flipCoordinates(_pArry){
var temp0=_pArry[0];
var result =[];
result[0]=_pArry[1];
result[1]=temp0;
return result;
}
function isOrderlowY(_obj1,_obj2){
var o1C=getCenter(_obj1);
var o2C=getCenter(_obj2);
if(o1C[1]<o2C[1]) return true;
else return false;
}
doc = activeDocument;
sel = doc.selection;
if (! sel.length==2) alert("select two objects you want to connect!");
else{
bLine=doc.pathItems.add();
bLine.filled = false; // 塗りなし
bLine.stroked = true; // 線あり
bLine.strokeWidth = 0.3; // 線幅1ポイント
var pts;
if(isOrderlowY(sel[0],sel[1]))pts=sel;
else pts=flipCoordinates(sel);
deltaY=(getCenter(pts[1])[1]-getCenter(pts[0])[1])/2.0;
pathObj=bLine.pathPoints.add();
pathObj.anchor = getCenter(pts[0]);
pathObj.leftDirection=[getCenter(pts[0])[0],-deltaY+getCenter(pts[0])[1]];
pathObj.rightDirection=[getCenter(pts[0])[0],+deltaY+getCenter(pts[0])[1]];
pathObj=bLine.pathPoints.add();
pathObj.anchor = getCenter(pts[1]);
pathObj.leftDirection=[getCenter(pts[1])[0],-deltaY+getCenter(pts[1])[1]];
pathObj.rightDirection=[getCenter(pts[1])[0],+deltaY+getCenter(pts[1])[1]];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment