Skip to content

Instantly share code, notes, and snippets.

@yasushisakai
Last active December 15, 2015 10:09
Show Gist options
  • Save yasushisakai/5244067 to your computer and use it in GitHub Desktop.
Save yasushisakai/5244067 to your computer and use it in GitHub Desktop.
script for illustrator connects two objects in a bezier curve (horizontal)
/**
* 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 isOrderlowX(_obj1,_obj2){
var o1C=getCenter(_obj1);
var o2C=getCenter(_obj2);
if(o1C[0]<o2C[0]) return true;
else return false;
}
//選択されたものが2であると仮定する
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(isOrderlowX(sel[0],sel[1]))pts=sel;
else pts=flipCoordinates(sel);
deltaX=(getCenter(pts[1])[0]-getCenter(pts[0])[0])/2.0;
pathObj=bLine.pathPoints.add();
pathObj.anchor = getCenter(pts[0]);
pathObj.leftDirection=[-deltaX+getCenter(pts[0])[0],getCenter(pts[0])[1]];
pathObj.rightDirection=[+deltaX+getCenter(pts[0])[0],getCenter(pts[0])[1]];
pathObj=bLine.pathPoints.add();
pathObj.anchor = getCenter(pts[1]);
pathObj.leftDirection=[-deltaX+getCenter(pts[1])[0],getCenter(pts[1])[1]];
pathObj.rightDirection=[+deltaX+getCenter(pts[1])[0],getCenter(pts[1])[1]];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment