CreatKey脚本ae

creatkey的ae脚本。

  • 判断文件是否存在
    1
    2
    3
    4
    5
    6
    //判断初始time文件是否存在,存在则读取
    filex='e://PycharmProjects//untitled2//chunks//df_time.xml';
    var flx=new File(filex);
    if (flx.exists){
    onLoadButtonClick(filex);
    }

版本20181205

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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
{
// Scale Selected Layers.jsx
//
// This script scales the selected layers within the active comp.
//
// First, it prompts the user for a scale_factor.
// Next, it scales all selected layers, including cameras.

function LoadKeyTimes(thisObj)
{
var scriptName = "Load Key Times: BY:AQ20181205";

var KeyTime=new Array();

// This variable stores the scale_factor.
var scale_factor = 1.0;
var scale_about_center = true;

var DDtime=false;
var wind;

//
// This function is called when the user clicks the "Scale about Upper Left" button
//
function onHelpButtonClick()
{
//scale_about_center = false;
//判断初始time文件是否存在,存在则读取
filex='e://PycharmProjects//untitled2//chunks//df_time.xml';
var flx=new File(filex);
if (flx.exists){
onLoadButtonClick(filex);
}
}


//
// This function is called when the user clicks the "Scale about Upper Left" button
//
function onLoadButtonClick(fs)
{
// 首先打开文件对话框
// 第一个参数是对话框的标题名
// 第二个参数是可供选择的文件类型(中括号里面可以写多个)
// 第三个是设置多选(`true`)还是单选(填`false`或不填)
// 此函数返回一个`file`类型的对象
// alert(fs);
// var file=File.openDialog ("Select an ass/txt file", ["XML:*.xml", "All files:*.*"], false);

var file = Object;
//file=File.openDialog ("Select an ass/txt file", ["XML:*.xml", "All files:*.*"], false);
if (fs===undefined) {
file=File.openDialog ("Select an ass/txt file", ["XML:*.xml", "All files:*.*"], false);
} else {
file =new File (fs);
}
//alert(file)
wind.file_input.text =file;
// alert(file)
// 设置该文件对象为可读模式(这一步很重要)
file.open('r'); // `r`为可读模式,`w`为可写模式,这两个是比较常用的(也可以留空)

// 读取文件内容
file = file.read(); // 读取全部内容
//file = file.read(5); // 读取5个字符
//file = file.readch(); // 读取单个字符
//file = file.readln(); // 读取一行内容

//file.open('w'); // 设置为“可写”模式
//file = file.write('hello world'); // 写入内容(会把原文件内容冲掉)

// 文本显示到编辑框中
//alert(file)
var re = /<start>([\s\S]+?)<\/start>/g;
var ii=0;
var timeS='';
while( tempR = re.exec(file))
{
// alert(tempR[1]);
var jx=parseInt(tempR[1])/25;
// alert(jx);
KeyTime[ii]=jx;

if (ii==0){
timeS=KeyTime[ii];
}else{
timeS=timeS + "," + KeyTime[ii];
}


ii=ii+1;
}

// alert(timeS);
wind.text_input.text = timeS;
DDtime=true;

}


//
// This function is called when the user enters text for the scale.
//
function on_textInput_changed()
{
// Set the scale_factor based on the text.
//var value = this.text;
//if (isNaN(value)) {
// alert(value + " is not a number. Please enter a number.", scriptName);
//} else {
// scale_factor = value;
// }
}


function onScaleClick()
{
var activeItem = app.project.activeItem;
if ((activeItem == null) || !(activeItem instanceof CompItem)) {
alert("Please select or open a composition first.", scriptName);
} else {
var selectedLayers = activeItem.selectedLayers;
if (activeItem.selectedLayers.length == 0) {
alert("Please select at least one layer in the active comp first.", 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;


//alert(activeItem.selectedLayers[0].property("Marker").keyValue().length);

var thisLayer=activeItem.selectedLayers[0];
var nKey=thisLayer.property("Marker").numKeys;
var Keycom= new Array();

//获取标记原来注释

for (var ii=1; ii<nKey+1; ii++)
{
Keycom[ii-1]=activeItem.selectedLayers[0].property("Marker").keyValue(ii).comment;
if (DDtime==false){
KeyTime[ii-1]=2*(ii-1);
}
}

//删除标记
for (var ii=1; ii<nKey+1; ii++)
{
activeItem.selectedLayers[0].property("Marker").removeKey(1);
}

//生成标记

for (var ii=1; ii<nKey+1; ii++)
{
var myMarker = new MarkerValue(Keycom[ii-1]);
// alert(Keycom[ii-1]);
activeItem.selectedLayers[0].property("Marker").setValueAtTime(KeyTime[ii-1], myMarker);
}



// alert(activeItem.selectedLayers[0].property("Marker").numKeys);
// alert(activeItem.selectedLayers[0].property("Marker").keyValue(1).comment);
// alert(activeItem.selectedLayers[0].property("Marker").keyValue(1).duration);
// var myMarker = new MarkerValue("淡入淡出2");
// thisLayer.property("Marker").setValueAtTime(2.5, myMarker);
// activeItem.selectedLayers[0].property("Marker").removeKey(1);

// myProperty = myTextLayer.sourceText;
// activeItem.selectedLayers[0].property("Marker").keyValue(1).setValueAtKey(1,new TextDocument("key number 1"))


//var commentOfFirstMarker =app.project.item(1).layer(1).property("Marker").keyValue(1).comment;
//var commentOfMarkerAtTime4 =app.project.item(1).layer(1).property("Marker").valueAtTime(4.0, true).comment
//var markerProperty = app.project.item(1).layer(1).property("Marker");
//var markerValueAtTimeClosestToTime4 =markerProperty.keyValue(markerProperty.nearestKeyIndex(4.0));
//var commentOfMarkerClosestToTime4 = markerValueAtTimeClosestToTime4.comment;

//alert(commentOfFirstMarker);
//alert(commentOfMarkerAtTime4);
//alert(markerProperty);
//alert(markerValueAtTimeClosestToTime4);
//alert(commentOfMarkerClosestToTime4);



}
}
}


//
// This function puts up a modal dialog asking for a scale_factor.
// Once the user enters a value, the dialog closes, and the script scales the comp.
//
function BuildAndShowUI(thisObj)
{
// Create and show a floating palette.
var my_palette = (thisObj instanceof Panel) ? thisObj : new Window("palette", scriptName, undefined, {resizeable:true});
if (my_palette != null)
{
var res =
"group { \
orientation:'column', alignment:['fill','top'], alignChildren:['left','top'], spacing:5, margins:[0,0,0,0], \
optsRow: Group { \
orientation:'column', alignment:['fill','top'], \
helpButton: Button { text:'Help', preferredSize:[150,20], alignment:['left','top'] }, \
file_input: EditText { text:'', alignment:['left','top'], preferredSize:[300,20],Multiline:true}, \
loadButton: Button { text:'Load Time', alignment:['fill','center'] }, \
text_input: EditText { text:'', alignment:['left','top'], preferredSize:[300,20], Multiline:true}, \
}, \
cmds: Group { \
alignment:['fill','top'], \
okButton: Button { text:'Do It', alignment:['fill','center'] }, \
}, \
}";

my_palette.margins = [10,10,10,10];
my_palette.grp = my_palette.add(res);

// Workaround to ensure the edittext text color is black, even at darker UI brightness levels.
var winGfx = my_palette.graphics;
var darkColorBrush = winGfx.newPen(winGfx.BrushType.SOLID_COLOR, [0,0,0], 1);
my_palette.grp.optsRow.text_input.graphics.foregroundColor = darkColorBrush;

my_palette.grp.optsRow.helpButton.onClick = onHelpButtonClick;
my_palette.grp.optsRow.loadButton.onClick = onLoadButtonClick;
//my_palette.grp.optsRow.loaddfButton.onClick = onLoaddfButtonClick;


// Set the callback. When the user enters text, this will be called.
my_palette.grp.optsRow.text_input.onChange = on_textInput_changed;
//my_palette.grp.optsRow.text_input.Multiline=true;

my_palette.grp.cmds.okButton.onClick = onScaleClick;

wind=my_palette.grp.optsRow;

my_palette.onResizing = my_palette.onResize = function () {this.layout.resize();}

//判断初始time文件是否存在,存在则读取
filex='e://PycharmProjects//untitled2//chunks//df_time.xml';
var flx=new File(filex);
if (flx.exists){
onLoadButtonClick(filex);
}



}

return my_palette;
}




//
// The main script.
//
if (parseFloat(app.version) < 8) {
alert("This script requires After Effects CS3 or later.", scriptName);
return;
}

//对话框打开文件




var my_palette = BuildAndShowUI(thisObj);
if (my_palette != null) {
if (my_palette instanceof Window) {
my_palette.center();
my_palette.show();
} else {
my_palette.layout.layout(true);
my_palette.layout.resize();
}
} else {
alert("Could not open the user interface.", scriptName);
}
}


LoadKeyTimes(this);
}

0%