-
Notifications
You must be signed in to change notification settings - Fork 0
/
testGround.jsx
250 lines (207 loc) · 7.02 KB
/
testGround.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<javascriptresource>
<name>-- TESTBED --</name>
<menu>filter</menu>
<category>Viera</category>
<type>automate</type>
<about>This will bake the selected adjustment layers to ALL layers below. - by Evan Viera</about>
<enableinfo>true</enableinfo>
</javascriptresource>
var doc = activeDocument;
var selectedLayer = doc.activeLayer;
var alertString = "" + selectedLayer.typename + ", " + selectedLayer.kind;
alert( alertString );
// doc.selection.load( doc.channels.getByName('Red') );
/*
app.activeDocument.channels.getByName( 'Red' );
var channelRef = [
doc.channels.getByName('Red'),
doc.channels.getByName('Green'),
doc.channels.getByName('Blue')
];
var layerParent = selectedLayer.parent;
var collectedLayers = [];
var layerIndex = 0;
// =======================================================
var idtoolModalStateChanged = stringIDToTypeID( "toolModalStateChanged" );
var desc517 = new ActionDescriptor();
var idLvl = charIDToTypeID( "Lvl " );
desc517.putInteger( idLvl, 1 );
var idStte = charIDToTypeID( "Stte" );
var idStte = charIDToTypeID( "Stte" );
var identer = stringIDToTypeID( "enter" );
desc517.putEnumerated( idStte, idStte, identer );
var idTool = charIDToTypeID( "Tool" );
var desc518 = new ActionDescriptor();
var idIdnt = charIDToTypeID( "Idnt" );
desc518.putString( idIdnt, """pntb""" );
var idTtl = charIDToTypeID( "Ttl " );
desc518.putString( idTtl, """Brush Tool""" );
var idTool = charIDToTypeID( "Tool" );
desc517.putObject( idTool, idTool, desc518 );
var idKnd = charIDToTypeID( "Knd " );
var idKnd = charIDToTypeID( "Knd " );
var idPnt = charIDToTypeID( "Pnt " );
desc517.putEnumerated( idKnd, idKnd, idPnt );
var idkcanDispatchWhileModal = stringIDToTypeID( "kcanDispatchWhileModal" );
desc517.putBoolean( idkcanDispatchWhileModal, true );
executeAction( idtoolModalStateChanged, desc517, DialogModes.NO );
// =======================================================
var idtoolModalStateChanged = stringIDToTypeID( "toolModalStateChanged" );
var desc519 = new ActionDescriptor();
var idLvl = charIDToTypeID( "Lvl " );
desc519.putInteger( idLvl, 0 );
var idStte = charIDToTypeID( "Stte" );
var idStte = charIDToTypeID( "Stte" );
var idexit = stringIDToTypeID( "exit" );
desc519.putEnumerated( idStte, idStte, idexit );
var idTool = charIDToTypeID( "Tool" );
var desc520 = new ActionDescriptor();
var idIdnt = charIDToTypeID( "Idnt" );
desc520.putString( idIdnt, """pntb""" );
var idTtl = charIDToTypeID( "Ttl " );
desc520.putString( idTtl, """Brush Tool""" );
var idTool = charIDToTypeID( "Tool" );
desc519.putObject( idTool, idTool, desc520 );
var idKnd = charIDToTypeID( "Knd " );
var idKnd = charIDToTypeID( "Knd " );
var idPnt = charIDToTypeID( "Pnt " );
desc519.putEnumerated( idKnd, idKnd, idPnt );
var idkcanDispatchWhileModal = stringIDToTypeID( "kcanDispatchWhileModal" );
desc519.putBoolean( idkcanDispatchWhileModal, true );
executeAction( idtoolModalStateChanged, desc519, DialogModes.NO );
var idColors = [ "Rd ", "Orng", "Ylw ", "Grn ", "Bl ", "Vlt ", "Gry " ];
var lastColor = 0;
alert( selectedLayer.name );
// group layer vegetables
var allLayers = new Array();
var artLayers = new Array();
var theLayers = collectAllLayers(app.activeDocument, 0);
var artLayerNames = "";
// loop over art layers backwards
for (var i = artLayers.length -1; i >= 0 ; i--)
{
var temp = artLayers[i];
var regEx = new RegExp(/t/gim);
if (temp.match(regEx))
{
// if the layer contains the letter "t" show it!
alert(temp);
}
artLayerNames+= artLayers[i] + "\n";
}
// print out all layers
alert(artLayerNames);
// function collect all layers
function collectAllLayers (theParent, level)
{
for (var m = theParent.layers.length - 1; m >= 0; m--)
{
var theLayer = theParent.layers[m];
// apply the function to layersets;
if (theLayer.typename == "ArtLayer")
{
// get the art layers
artLayers.push(theLayer.name);
}
else
{
allLayers.push(level + theLayer.name);
collectAllLayers(theLayer, level + 1)
}
}
}
layerIndex = getIndex( );
if ( selectedLayer.grouped == true )
{
collectClippingLayersBelow( );
}
else
{
collectLayersBelow( layerIndex, layerParent );
}
executeTempAction( );
// ****************************************
// Returns the index of the selected layer
// ****************************************
function getIndex( )
{
var index = 0;
while ( layerParent.layers[ index ] != selectedLayer )
{
index++;
}
return index;
}
// ****************************************
// Collects all layers underneat into array
// ****************************************
function collectLayersBelow( __index, __parent )
{
for ( var i = __index; i < __parent.layers.length; i++ ) {
var currentLayer = __parent.layers[ i ];
if ( currentLayer.typename == "ArtLayer" ) {
if ( currentLayer.visible == true ) {
if ( currentLayer.kind == LayerKind.NORMAL ) {
collectedLayers.push( currentLayer );
}
}
}
else {
collectLayersBelow( 0, currentLayer );
}
}
}
// ****************************************
// Collects all layers underneat into array
// ****************************************
function collectClippingLayersBelow( )
{
var i = layerIndex;
var currentLayer = layerParent.layers[ i ];
while ( currentLayer.grouped == true )
{
currentLayer = layerParent.layers[ i ];
// If current layer is a folder ("grouped") then collectLayersBelow
if ( currentLayer.typename == "LayerSet" ) collectLayersBelow( 0, currentLayer );
if ( currentLayer.typename == "ArtLayer" ) collectedLayers.push( currentLayer );
i++;
}
}
// ****************************************
// Executes actions for all layers in array
// ****************************************
function executeTempAction( )
{
for ( var i = 0; i < collectedLayers.length; i++ ) {
doc.activeLayer = collectedLayers[i];
doc.activeLayer.name = doc.activeLayer.parent + i;
setLabelColor( idColors[ lastColor ] );
lastColor = (lastColor + 1) % idColors.length;
}
}
// ****************************************
// Sets label color to parameters def
// ****************************************
function setLabelColor( setTo )
{
var idsetd = charIDToTypeID( "setd" );
var desc85 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref33 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref33.putEnumerated( idLyr, idOrdn, idTrgt );
desc85.putReference( idnull, ref33 );
var idT = charIDToTypeID( "T " );
var desc86 = new ActionDescriptor();
var idClr = charIDToTypeID( "Clr " );
var idClr = charIDToTypeID( "Clr " );
var idRd = charIDToTypeID( setTo );
desc86.putEnumerated( idClr, idClr, idRd );
var idLyr = charIDToTypeID( "Lyr " );
desc85.putObject( idT, idLyr, desc86 );
executeAction( idsetd, desc85, DialogModes.NO );
return;
}
*/