-
Notifications
You must be signed in to change notification settings - Fork 10
/
Toggle Maintain Scale Expression.jsx
54 lines (51 loc) · 2.11 KB
/
Toggle Maintain Scale Expression.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
/**
* @name Toggle Maintain Scale Expression
* @version 1.0
* @author Kyle Martinez <www.kyle-martinez.com>
*
* @description Disable or enable an expression that maintains the visual scale of a layer as it's
* positioned in Z Space.
*
* @license This script is provided "as is," without warranty of any kind, expressed or implied. In
* no event shall the author be held liable for any damages arising in any way from the use of this
* script.
*
* In other words, I'm just trying to help make life as an animator easier
* "A rising tide lifts all boats." - John F. Kennedy, 1963
*/
(function() {
function disableScaleExpression (layer) {
var scaleProperty = layer.transform.scale;
var scaleValue = scaleProperty.value;
scaleProperty.expression = "";
scaleProperty.setValue(scaleValue);
}
function enableScaleExpression (layer) {
var scaleProperty = layer.transform.scale;
var scaleValue = scaleProperty.value[0];
var positionValue = layer.transform.position.value[2];
var zoomValue = layer.containingComp.width / 0.72;
if (layer.containingComp.activeCamera !== null) {
zoomValue = layer.containingComp.activeCamera.cameraOption.zoom.value;
}
var value = scaleValue / (1 + (positionValue / zoomValue));
scaleProperty.setValue([value, value, value]);
scaleProperty.expression = ["try { var zoom = thisComp.activeCamera.cameraOption.zoom; } catch (e) { var zoom = thisComp.width / 0.72; }",
"value * (1 + (transform.position[2] / zoom));"].join("\n");
}
app.beginUndoGroup("Toggle Maintain Scale Expression");
var comp = app.project.activeItem;
var layers = comp.selectedLayers;
var numLayers = layers.length;
for (var l = 0; l < numLayers; l++) {
var layer = layers[l];
if (layer.threeDLayer === true) {
if (layer.transform.scale.expression.length > 0) {
disableScaleExpression(layer);
} else {
enableScaleExpression(layer);
}
}
}
app.endUndoGroup();
})();