Last active
August 17, 2019 12:35
-
-
Save cg-method/8f38baf136ad741981c78997dddda0a8 to your computer and use it in GitHub Desktop.
【Illustrator】オフセットできるトンボ作成(西洋式)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var value = prompt("オブジェクトからトンボまでのオフセット値を入力してください(デフォルト8)", "8"); | |
var value = eval(value); | |
var stroke = 0.3; | |
var selObj = activeDocument.selection; | |
for (var i = 0; i < selObj.length; i++) { | |
var rect = selObj[i].geometricBounds; | |
var x1 = rect[0]; | |
var y1 = rect[1]; | |
var x2 = rect[2]; | |
var y2 = rect[3]; | |
var d = 20; //線の長さ | |
var o = value + stroke; | |
//西洋式トンボ | |
drawLine2(x1, y1 + o, x1, y1 + o + d) //左上縦 | |
drawLine2(x1 - o, y1, x1 - o - d, y1) //左上横 | |
drawLine2(x2, y1 + o, x2, y1 + o + d) //右上縦 | |
drawLine2(x2 + o, y1, x2 + o + d, y1) //左上横 | |
drawLine2(x1, y2 - o, x1, y2 - o - d) //左下縦 | |
drawLine2(x1 - o, y2, x1 - o - d, y2) //左下横 | |
drawLine2(x2, y2 - o, x2, y2 - o - d) //右下縦 | |
drawLine2(x2 + o, y2, x2 + o + d, y2) //左下横 | |
} | |
// 線を描画(始点・終点の座標・2点) | |
function drawLine2(sx, sy, ex, ey) { | |
var pObj = app.activeDocument.pathItems.add(); | |
pObj.setEntirePath([ | |
[sx, sy], | |
[ex, ey] | |
]); | |
pObj.filled = false; // 塗りなし | |
pObj.stroked = true; // 線あり | |
pObj.strokeWidth = 0.3; // 線幅1ポイント | |
pObj.strokeColor = setColor(255, 0, 0); // 線の色を指定 | |
//pObj.guides = true; | |
} | |
// カラーを設定 | |
function setColor(r, g, b) { | |
var tmpColor = new RGBColor(); | |
tmpColor.red = r; | |
tmpColor.green = g; | |
tmpColor.blue = b; | |
return tmpColor; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment