-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathrectToLine.jsx
More file actions
35 lines (34 loc) · 965 Bytes
/
rectToLine.jsx
File metadata and controls
35 lines (34 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*Adobe Illustrators Javascript.
Convert Rectangles to lines Sample code.
*/
(function (){
var tg = app.selection;
for (var i=0;i<tg.length;i++){
if (tg[i].typename!="PathItem") continue;
var ln = app.activeDocument.pathItems.add();
ln.filled = false;
ln.strokeColor = tg[i].fillColor;
if (tg[i].width>tg[i].height){
addPoint(ln, [tg[i].geometricBounds[0],
tg[i].geometricBounds[1] - tg[i].height / 2]);
addPoint(ln, [tg[i].geometricBounds[2],
tg[i].geometricBounds[1] - tg[i].height / 2]);
ln.strokeWidth = tg[i].height;
}
else{
addPoint(ln, [tg[i].geometricBounds[0] + tg[i].width / 2,
tg[i].geometricBounds[1]]);
addPoint(ln, [tg[i].geometricBounds[0] + tg[i].width / 2,
tg[i].geometricBounds[3]]);
ln.strokeWidth = tg[i].width;
}
tg[i].remove();
}
function addPoint(tgt, pos){
var pt = tgt.pathPoints.add();
pt.anchor = pos;
pt.leftDirection = pos;
pt.rightDirection = pos;
}
}
)();