-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReverse.jsx
90 lines (73 loc) · 2.35 KB
/
Reverse.jsx
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Reverse
// reverses the order of the anchor points of each selected paths
// test env: Adobe Illustrator CS3, CS6 (Windows)
// Copyright(c) 2004-2013 Hiroyuki Sato
// https://github.com/shspage
// This script is distributed under the MIT License.
// See the LICENSE file for details.
// Wed, 30 Jan 2013 07:09:23 +0900
main();
function main(){
var paths = [];
getPathItemsInSelection(1, paths);
if(paths.length<1) return;
for(var i = 0; i < paths.length; i++){
pireverse( paths[i] );
}
/*
// show alert when done
var str = paths.length == 1 ? " path" : " paths";
alert( paths.length + str + " reversed" );
*/
}
// -----------------------------------------
function pireverse(pi){
var p = pi.pathPoints;
var ps = [];
var i;
for(i = 0; i < p.length; i++) {
with(p[i]){
ps.unshift([anchor, rightDirection, leftDirection, pointType]);
}
}
for(i = 0; i < p.length; i++) {
with(p[i]){
anchor = ps[i][0];
leftDirection = ps[i][1];
rightDirection = ps[i][2];
pointType = ps[i][3];
}
}
}
// ------------------------------------------------
// extract PathItems from the selection which length of PathPoints
// is greater than "n"
function getPathItemsInSelection(n, paths){
if(documents.length < 1) return;
var s = activeDocument.selection;
if (!(s instanceof Array) || s.length < 1) return;
extractPaths(s, n, paths);
}
// --------------------------------------
// extract PathItems from "s" (Array of PageItems -- ex. selection),
// and put them into an Array "paths". If "pp_length_limit" is specified,
// this function extracts PathItems which PathPoints length is greater
// than this number.
function extractPaths(s, pp_length_limit, paths){
for(var i = 0; i < s.length; i++){
if(s[i].typename == "PathItem"){
if(pp_length_limit
&& s[i].pathPoints.length <= pp_length_limit){
continue;
}
paths.push(s[i]);
} else if(s[i].typename == "GroupItem"){
// search for PathItems in GroupItem, recursively
extractPaths(s[i].pageItems, pp_length_limit, paths);
} else if(s[i].typename == "CompoundPathItem"){
// searches for pathitems in CompoundPathItem, recursively
// ( ### Grouped PathItems in CompoundPathItem are ignored ### )
extractPaths(s[i].pathItems, pp_length_limit , paths);
}
}
}