-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathscale all comps in project panel.jsx
110 lines (88 loc) · 3.6 KB
/
scale all comps in project panel.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
(function(thisObj) {// ~ scale all comps in panel
run(thisObj);
function run(thisObj) {
var data = {
scale_factor: 4.0,
scirptname: File($.fileName)
};
doScale(data);
}
// var curComp = app.project.activeItem;
// if (!curComp || !(curComp instanceof CompItem)){
// alert("noComp");
// return;
// };
//
function doScale(data) {
// By bracketing the operations with begin/end undo group, we can
// undo the whole script with one undo operation.
app.beginUndoGroup('do sale');
for(var i = 0; i < app.project.selection.length; i++) {
var activeItem = app.project.selection[i];// = app.project.activeItem;
if ((activeItem === null) || !(activeItem instanceof CompItem)) {
alert('Please select or open a composition first.', data.scriptName);
} else {
// Validate the input field, in case the user didn't defocus it first (which often can be the case).
// this.parent.parent.optsRow.text_input.notify("onChange");
var activeComp = activeItem;
// app.beginUndoGroup(data.scriptName);
// Create a null 3D layer.
var null3DLayer = activeItem.layers.addNull();
null3DLayer.threeDLayer = true;
// Set its position to (0,0,0).
null3DLayer.position.setValue([0, 0, 0]);
// Set null3DLayer as parent of all layers that don't have parents.
makeParentLayerOfAllUnparented(activeComp, null3DLayer);
// Set new comp width and height.
activeComp.width = Math.floor(activeComp.width * data.scale_factor);
activeComp.height = Math.floor(activeComp.height * data.scale_factor);
// Then for all cameras, scale the Zoom parameter proportionately.
scaleAllCameraZooms(activeComp, data.scale_factor);
// Set the scale of the super parent null3DLayer proportionately.
var superParentScale = null3DLayer.scale.value;
superParentScale[0] *= data.scale_factor;
superParentScale[1] *= data.scale_factor;
superParentScale[2] *= data.scale_factor;
null3DLayer.scale.setValue(superParentScale);
// Delete the super parent null3DLayer with dejumping enabled.
null3DLayer.remove();
// app.endUndoGroup();
// Reset data.scale_factor to 1.0 for next use.
// ~ data.scale_factor = 1.0;
// ~ if (this.parent.parent.optsRow.scaleButton.value) {
// ~ this.parent.parent.optsRow.text_input.text = "1.0";
// ~ }
}
}
app.endUndoGroup();
} // close onScaleClick
//
// Scales the zoom factor of every camera by the given scale_factor.
// Handles both single values and multiple keyframe values.
function scaleAllCameraZooms(theComp, scaleBy) {
for (var i = 1; i <= theComp.numLayers; i++) {
var curLayer = theComp.layer(i);
if (curLayer.matchName === 'ADBE Camera Layer') {
var curZoom = curLayer.zoom;
if (curZoom.numKeys === 0) {
curZoom.setValue(curZoom.value * scaleBy);
} else {
for (var j = 1; j <= curZoom.numKeys; j++) {
curZoom.setValueAtKey(j, curZoom.keyValue(j) * scaleBy);
}
}
}
}
}
// Sets newParent as the parent of all layers in theComp that don't have parents.
// This includes 2D/3D lights, camera, av, text, etc.
//
function makeParentLayerOfAllUnparented(theComp, newParent) {
for (var i = 1; i <= theComp.numLayers; i++) {
var curLayer = theComp.layer(i);
if (curLayer !== newParent && curLayer.parent === null) {
curLayer.parent = newParent;
}
}
}
}(this));