forked from johnwun/js4ai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sharpenCorners.js
90 lines (79 loc) · 2.5 KB
/
sharpenCorners.js
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
/////////////////////////////////////////////////////////////////
// Sharpen Corners -- CS,CS2
//>=--------------------------------------
//
// Removes control handles from selected path points.
// Works same as clicking a point with the convert anchor point tool,
// but enmass on all selected points.
//
// An option is provided for zeroing the control handles of adjacent points.
//
//
//>=--------------------------------------
// JS code (c) copyright: John Wundes ( [email protected] ) www.wundes.com
//copyright full text here: http://www.wundes.com/js4ai/copyright.txt
//////////////////////////////////////////////////////////////////
var doc = activeDocument;
var sel = doc.selection;
var sellen = sel.length;
//
var ignoredItemCount = 0;
//
var adjacentHandlesToo=1;
// The 'adjacentHandlesToo' variable is a toggle for zeroing the handles of adjacent points.
// I default this to true because in most cases, I assume this will
// be the expected behavior. If not, set to 0.
var ui = confirm("Remove shared control handles from adjacent points?");
if( ui == true){
adjacentHandlesToo=ui;
}
//
//---------------------------------------main code:
//
for(var x=0;x<sellen;x++){
if(sel[x].typename == "PathItem"){
// hose control points of selected path items
hoseHandles(sel[x]);
}else if(sel[x].typename == "CompoundPathItem"){
//hose control points of selected compound path items
var cpiLen = sel[x].pathItems.length;
for (var j=0;j<cpiLen;j++){
hoseHandles(sel[x].pathItems[j]);
}
}else{
ignoredItemCount ++;
}
}
if(ignoredItemCount>0){
alert("Just so you know:\n"+ignoredItemCount+" Item(s) ignored. \nTry selecting objects individually or ungrouping.");
}
//------------------------------functions below:
function hoseThisAnchor(ptOb,deets){
var anch = ptOb.anchor;
var cntr_arr = Array(anch[0],anch[1]);
if(deets=='l'){
ptOb.leftDirection = cntr_arr;
} else if(deets=="r"){
ptOb.rightDirection = cntr_arr;
} else {
ptOb.leftDirection = cntr_arr;
ptOb.rightDirection = cntr_arr;
}
}
function hoseHandles(ob){
var ppl = ob.pathPoints.length;
for(var y=0;y<ppl;y++){
//This
if(ob.pathPoints[y].selected==PathPointSelection.ANCHORPOINT){
hoseThisAnchor(ob.pathPoints[y]);
}
if(adjacentHandlesToo==1){
if(ob.pathPoints[y].selected==PathPointSelection.LEFTDIRECTION){
hoseThisAnchor(ob.pathPoints[y],'l');
}
if(ob.pathPoints[y].selected==PathPointSelection.RIGHTDIRECTION){
hoseThisAnchor(ob.pathPoints[y],'r');
}
}
}
}