forked from ff6347/after-effects-script-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
every selected comp in project panel.jsx
206 lines (170 loc) · 6.99 KB
/
every selected comp 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
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
// Copyright (c) 2013
// Fabian "fabiantheblind" Morón Zirfas
// for all comps in panel
//
// do something
//
// Permission is hereby granted, free of charge, to any
// person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to
// whom the Software is furnished to do so, subject to
// the following conditions:
// The above copyright notice and this permission notice
// shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTIO
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// see also http://www.opensource.org/licenses/mit-license.php
(function(thisObj) {
run(thisObj);
function run(thisObj) {
var script_data = {
scale_factor: 4.0,
scirptname: File($.fileName),
presets: {
path: '/Applications/Adobe After Effects CS6/Presets/User Presets/volkswagen/',
names: [
'[VolksWagen Besucherdienste] placeholder quick and dirty key.ffx'
]
}
};
doApplyPreset(script_data);
// doScale(script_data);
}
// var curComp = app.project.activeItem;
// if (!curComp || !(curComp instanceof CompItem)){
// alert("noComp");
// return;
// };
// | |
// __ _ _ __ _ __ | |_ _
// / _` | '_ \| '_ \| | | | |
// | (_| | |_) | |_) | | |_| |
// \__,_| .__/| .__/|_|\__, |
// | | | | __/ |
// |_| |_| |___/
// _____ _
// | __ \ | |
// | |__) | __ ___ ___ ___| |_
// | ___/ '__/ _ \/ __|/ _ \ __|
// | | | | | __/\__ \ __/ |_
// |_| |_| \___||___/\___|\__|
function doApplyPreset(data) {
var preset = null;
var presetFile = File(data.presets.path + data.presets.names[0]);
if(presetFile.exists === false) {
alert('preset file does not exist');
return;
}
app.beginUndoGroup('do presetFile');
var errlog = '';
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)) {
errlog += ('Please select or open a composition first.' + data.scriptName);
} else {
// var activeComp = activeItem;
for (var j = 1; j <= activeItem.numLayers; j++) {
var curLayer = activeItem.layer(j);
curLayer.selected = true;
curLayer.applyPreset(presetFile);
} // end j loop
} // end else active item not a comp
} // end i loop
app.endUndoGroup();
alert('error log' + errlog);
presetFile.close();// always close files
}
// ------------ end of apply preset ------------
// _____ _____ _ ______
// / ____|/ ____| /\ | | | ____|
// | (___ | | / \ | | | |__
// \___ \| | / /\ \ | | | __|
// ____) | |____ / ____ \| |____| |____
// |_____/ \_____/_/ \_\______|______|
/**
* the following functions are taken from the Scale Composition.jsx delivered with AE by Adobe
* @param {[type]} data [description]
* @return {[type]} [description]
*/
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;
}
}
}
// ------------ end of scale functions ------------
}(this));