-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathImageTracing.jsx
executable file
·118 lines (95 loc) · 3.82 KB
/
ImageTracing.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**********************************************************
ADOBE SYSTEMS INCORPORATED
Copyright 2005-2012 Adobe Systems Incorporated
All Rights Reserved
NOTICE: Adobe permits you to use, modify, and
distribute this file in accordance with the terms
of the Adobe license agreement accompanying it.
If you have received this file from a source
other than Adobe, then your use, modification,
or distribution of it requires the prior
written permission of Adobe.
*********************************************************/
/**********************************************************
ImageTracing.jsx
DESCRIPTION
This sample gets files specified by the user from the
selected folder and batch processes them and saves them
as AI files in the user desired destination with the same
file name after tracing the raster arts in the files.
**********************************************************/
// Main Code [Execution of script begins here]
// uncomment to suppress Illustrator warning dialogs
// app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
// Collectable files
var COLLECTABLE_EXTENSIONS = ["bmp", "gif", "giff", "jpeg", "jpg", "pct", "pic", "psd", "png", "tif", "tiff"];
var destFolder, sourceFolder;
// Select the source folder
sourceFolder = Folder.selectDialog( 'Select the SOURCE folder...', '~' );
//sourceFolder = new Folder("C:/Users/<Username>/Desktop/1");
if(sourceFolder != null)
{
// Select the destination folder
destFolder = Folder.selectDialog( 'Select the DESTINATION folder...', '~' );
//destFolder = new Folder("C:/Users/<Username>/Desktop/2");
}
if(sourceFolder != null && destFolder != null)
{
//getting the list of the files from the input folder
var fileList = sourceFolder.getFiles();
var errorList;
var tracingPresets = app.tracingPresetsList;
for (var i=0; i<fileList.length; ++i)
{
if (fileList[i] instanceof File)
{
try
{
var fileExt = String(fileList[i]).split (".").pop();
if(isTraceable(fileExt) != true)
continue;
// Trace the files by placing them in the document.
// Add a document in the app
var doc = app.documents.add();
// Add a placed item
var p = doc.placedItems.add();
p.file = new File(fileList[i]);
// Trace the placed item
var t = p.trace();
t.tracing.tracingOptions.loadFromPreset(tracingPresets[3]);
app.redraw();
var destFileName = fileList[i].name.substring(0, fileList[i].name.length - fileExt.length-1) + "_" +fileExt;
var outfile = new File(destFolder+"/"+destFileName);
doc.saveAs(outfile);
doc.close();
}
catch (err)
{
errorStr = ("Error while tracing "+ fileList[i].name +".\n" + (err.number & 0xFFFF) + ", " + err.description);
// alert(errorStr);
errorList += fileList[i].name + " ";
}
}
}
fileList = null;
alert("Batch process complete.");
}
else
{
alert("Batch process aborted.");
}
sourceFolder = null;
destFolder = null;
function isTraceable(ext)
{
var result = false;
for (var i=0; i<COLLECTABLE_EXTENSIONS.length; ++i)
{
if(ext == COLLECTABLE_EXTENSIONS[i])
{
result = true;
break;
}
}
return result;
}