-
Notifications
You must be signed in to change notification settings - Fork 5
/
paths_to_scad.jsx
66 lines (57 loc) · 2.28 KB
/
paths_to_scad.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
// from https://github.com/jk-keller/Adobe-Scripts/blob/master/paths_to_scad.jsx
#target illustrator
var docRef = app.activeDocument;
var selRef = docRef.selection;
var strPolygons = "";
if (selRef.length == 0) {
alert("You gotta select something, buster.");
} else {
for (i=0; i<selRef.length; i++) {
var strPoints = "polygon(points=[";
var strPaths = "], paths=[[";
var pathsCounter = 0;
var pathRef = selRef[i];
if (pathRef.typename == "GroupItem") {
alert("Grouped items don't work just yet.");
} else if (pathRef.typename == "CompoundPathItem") {
for (j=0; j<pathRef.pathItems.length; j++) {
if (j != 0) {
strPoints += ",";
strPaths += "],[";
}
for (k=0; k<pathRef.pathItems[j].pathPoints.length; k++) {
var tempX = Math.round(pathRef.pathItems[j].pathPoints[k].anchor[0]/.02834645)/100;
var tempY = Math.round(pathRef.pathItems[j].pathPoints[k].anchor[1]/.02834645)/100;
if (k != 0) {
strPoints += ",";
strPaths += ",";
}
strPoints += "["+tempX+","+tempY+"]";
strPaths += pathsCounter;
pathsCounter++;
}
}
strPaths += "]]);";
strPolygons += strPoints + strPaths;
} else {
for (j=0; j<pathRef.pathPoints.length; j++) {
if (j != 0) {
strPoints += ",";
}
var tempX = Math.round(pathRef.pathPoints[j].anchor[0]/.2834645)/10;
var tempY = Math.round(pathRef.pathPoints[j].anchor[1]/.2834645)/10;
strPoints += "["+tempX+","+tempY+"]";
}
strPoints += "]);";
strPolygons += strPoints;
}
}
var tName = prompt("Document Name \r .scad extension added automatically. Will overwrite files without warning!", "output");
if (tName != null) {
var textFile = File('~/Desktop/'+tName+'.scad');
textFile.open('e');
textFile.write(strPolygons);
textFile.close();
alert("Yay! Check your desktop.");
}
}