-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathConvert New Gaussian Blur To Old.jsx
70 lines (59 loc) · 1.93 KB
/
Convert New Gaussian Blur To Old.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
/**
* Convert the new (CC 2015.3+) Gaussian Blur effect to Gaussian Blur (Legacy).
*
* @author Zack Lovatt <[email protected]>
* @version 1.0.2
*/
(function convertNewGBlurToOld() {
function getBlurData(effect) {
return {
blurIdx: effect.propertyIndex,
blurName: effect.name,
blurVal: effect.property(1).value,
blurDir: effect.property(2).value,
};
}
function removeOldBlurs(layerEffects, blurDataArray) {
for (var ii = blurDataArray.length - 1; ii >= 0; ii--) {
var thisIdx = blurDataArray[ii].blurIdx;
layerEffects.property(thisIdx).remove();
}
}
function buildNewEffects(layerEffects, blurDataArray) {
for (var ii = 0, il = blurDataArray.length; ii < il; ii++) {
var newBlur = layerEffects.addProperty('ADBE Gaussian Blur');
newBlur.property(1).setValue(blurDataArray[ii].blurVal);
newBlur.property(2).setValue(blurDataArray[ii].blurDir);
newBlur.name = blurDataArray[ii].blurName;
newBlur.moveTo(blurDataArray[ii].blurIdx);
}
}
function iterateThroughEffects(layer) {
var layerEffects = layer.property('Effects');
var blurDataArray = [];
for (var ii = 1, il = layerEffects.numProperties; ii <= il; ii++) {
var effect = layerEffects(ii);
if (effect.matchName !== 'ADBE Gaussian Blur 2') {
continue;
}
blurDataArray.push(getBlurData(effect));
}
removeOldBlurs(layerEffects, blurDataArray);
buildNewEffects(layerEffects, blurDataArray);
}
function iterateThroughSelectedLayers(layers) {
for (var ii = 0, il = layers.length; ii < il; ii++) {
var layer = layers[ii];
iterateThroughEffects(layer);
}
}
var comp = app.project.activeItem;
if (!(comp && comp instanceof CompItem)) {
alert('Open a comp!');
return;
}
var layers = comp.selectedLayers;
app.beginUndoGroup('New Blur to Old Blur');
iterateThroughSelectedLayers(layers);
app.endUndoGroup();
})();