License Public Domain
Lines 112
Keywords
Illustrator (1) javascript (9) layers (1)
Permissions
Owner: Jess Kerlin
Viewable by Everyone
Editable by All Siafoo Users
Hide
Meet people who work on similar things as you – get help if you need it Join Siafoo Now or Learn More

Example Illustrator CS2 Script for Making Stimuli from Root Layers Atom Feed 0

In Brief This was written to automatically make stimuli for a psychology experiment. The AI file had a lot of layers, which had stimuli at different locations.
# 's
  1var i, j, k, m ,h ,sourceDoc, targetFile, TColor, DColor;
2
3var destFolder = null;
4// Get the destination to save the files
5destFolder = Folder.selectDialog( 'Select the folder where you want to save the exported files.', '~' );
6
7 // Create a red RGB color object for brush color
8 //Bright Color
9 my1Color = new RGBColor();
10 my1Color.red = 255;
11 my1Color.green = 0;
12 my1Color.blue = 0;
13 // Dim Color
14 my2Color = new RGBColor();
15 my2Color.red = 50;
16 my2Color.green = 50;
17 my2Color.blue = 50;
18 // Background Color
19 myGColor = new RGBColor();
20 myGColor.red = 192;
21 myGColor.green = 192;
22 myGColor.blue = 192;
23 mString = new Array("r","d");
24 kString = new Array("r","d");
25 hString = new Array("large","small");
26
27if(documents.length > 0) {
28 doc = activeDocument;
29
30 // clear the old selection
31 //doc.selection = null;
32
33 // Get the pth items
34 myPaths = doc.pathItems;
35 for (m=0; m<2; m++){ //Distrator color
36 DColor = my1Color;
37
38 for (k=0; k<2; k++){//Target color
39 TColor = my1Color;
40
41 for (j = 48+24; j<57+24; j++){//Distractor
42 circle = "" + j;
43 if(m == 1){
44 DColor = my2Color;
45 }
46 if(j != 48+24){
47 myPaths[j].fillColor = DColor;
48 }
49 redraw();
50 for(h=0; h<2; h++){ // Target size
51
52 // For each of the path items
53 for(i=0; i<25; i++) { //Target
54 ind = i;
55 if(h == 1){
56 ind = i + 24;
57 }
58 doc.selection = null;
59
60
61 //alert(bline);
62 if(k == 1){
63 TColor = my2Color;
64 }
65
66 if(i > 0){
67 if(h ==1){
68 myPaths[ind+24].opacity = 0;
69 }
70 myPaths[ind].fillColor = TColor;
71 myPaths[ind].opacity = 100;
72 }
73
74
75 redraw();
76
77 tsize = hString[h];
78 tcolor = kString[k];
79 dcolor = mString[m];
80 target = "" + i;
81 distractor = "" + (j-(48+24));
82 sourceDoc = activeDocument; // returns the document object
83 s1 = tsize + '_' + tcolor + dcolor + '_' + target + '_' + distractor;
84 targetFile = getNewName(sourceDoc, destFolder, s1);
85 //Export to bmp
86 sourceDoc.exportFile(targetFile, ExportType.PNG24);
87
88
89 if(i > 0){
90 myPaths[ind].opacity = 0;
91 myPaths[ind+24].opacity = 100;
92 myPaths[ind].fillColor = myGColor;
93 }
94 redraw();
95 }
96
97 }
98 myPaths[j].opacity = 100;
99 myPaths[j].fillColor = myGColor;
100
101 redraw();
102 }
103
104 }
105 }
106}
107
108
109
110function getNewName(sourceDoc, destFolder, s1) {
111 var docName = sourceDoc.name;
112 var ext = '.png'; //
113 var newName = "";
114
115 if (docName.indexOf('.') < 0) {
116 newName = s1 + ext;
117 } else {
118 var dot = docName.lastIndexOf('.');
119 newName += s1;
120 newName += ext;
121 }
122
123 // Create a file object to save the png
124 saveInFile = new File( destFolder + '/' + newName + s1);
125 return saveInFile;
126}

This was written to automatically make stimuli for a psychology experiment. The AI file had a lot of layers, which had stimuli at different locations.