-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEF_FindAndReplaceLayer.jsx
48 lines (40 loc) · 1.73 KB
/
EF_FindAndReplaceLayer.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
/**========================================================================
* ? EF_FindAndReplaceLayer.jsx
* @author Eveline Falcão <https://evelinefalcao.com>
* @email [email protected]
* @version 1.0.0
* @createdFor Adobe After Effects CC 2024 (Version 24.1.0 Build 78)
* @description Find a layer by name and replace it with another item. Is case sensitive.
*========================================================================**/
(function findAndReplaceLayer(){
var comps = app.project.selection;
var layerInput = prompt("Type the Layer Name you wish to replace:", "Layer Name");
if (layerInput) {
var targetLayerName = layerInput.toString();
}
var sourceInput = prompt("Type the Item Name you wish to replace the layer with:", "Source Name");
if (sourceInput) {
var targetSourceName = sourceInput.toString();
}
var projectItems = app.project.items;
for (var item = 1; item <= projectItems.length; item++) {
if (projectItems[item].name == targetSourceName) {
var targetSource = projectItems[item];
}
}
app.beginUndoGroup("'Replace Layers'");
for (var item = 0; item < comps.length; item++) {
var curItem = comps[item];
if (curItem instanceof CompItem) {
var layers = curItem.layers;
for (var layer = 1; layer <= layers.length; layer++) {
var currentLayer = layers[layer];
var curLayerName = currentLayer.name;
if (curLayerName == targetLayerName) {
currentLayer.replaceSource(targetSource, true);
}
}
}
}
app.endUndoGroup();
})();