为AE使用的脚本,用于模拟时钟的运动效果。
function SecondHandEffectScript() {
var scriptWindow = new Window("palette", "时钟效果器1.1 作者 b站:吾秀的丫批", undefined, {resizeable: true});
scriptWindow.orientation = "column";
scriptWindow.alignChildren = ["fill", "fill"];
scriptWindow.layerText = scriptWindow.add("statictext", undefined, "已选择的图层:无");
scriptWindow.selectButton = scriptWindow.add("button", undefined, "选择图层");
var selectedLayer = null;
scriptWindow.grp = scriptWindow.add("group");
scriptWindow.grp.orientation = "row";
scriptWindow.grp.add("statictext", undefined, "每秒刷新次数:");
var ticksField = scriptWindow.grp.add("edittext", undefined, "1");
ticksField.characters = 4;
scriptWindow.grp.add("statictext", undefined, "每次移动角度:");
var degreesField = scriptWindow.grp.add("edittext", undefined, "6");
degreesField.characters = 4;
scriptWindow.predefinedType = scriptWindow.add("dropdownlist", undefined, ["自定义", "秒针", "分针", "时针"]);
scriptWindow.predefinedType.selection = 0;
scriptWindow.refreshController = scriptWindow.add("checkbox", undefined, "启用刷新控制(不启用则进行平滑运动)");
var applyButton = scriptWindow.add("button", undefined, "应用效果");
scriptWindow.selectButton.onClick = function () {
var comp = app.project.activeItem;
if (comp && comp instanceof CompItem && comp.selectedLayers.length == 1) {
selectedLayer = comp.selectedLayers[0];
scriptWindow.layerText.text = "已选择的图层:" + selectedLayer.name;
} else {
alert("请在当前合成中选择一个图层。");
}
};
scriptWindow.predefinedType.onChange = function () {
var preset = scriptWindow.predefinedType.selection.index;
switch (preset) {
case 1:
// 秒针预设
ticksField.text = "1";
degreesField.text = "6";
break;
case 2:
// 分针预设
ticksField.text = "1";
degreesField.text = "1/10";
break;
case 3:
// 时针预设
ticksField.text = "1";
degreesField.text = "1/120";
break;
}
};
applyButton.onClick = function () {
if (selectedLayer === null) {
alert("请先选择一个图层。");
return;
}
app.beginUndoGroup("应用时钟效果");
var effectExpression = "ticksPerSecond = " + ticksField.text + ";\n" +
"degreesPerTick = " + degreesField.text + ";\n" +
"frameRate = 1 / thisComp.frameDuration;\n" +
"ticks = Math.floor(time * frameRate);\n" +
"ticksPerFrame = frameRate / ticksPerSecond;\n";
if (scriptWindow.refreshController.value) {
effectExpression += "Math.floor(ticks / ticksPerFrame) * degreesPerTick;";
} else {
effectExpression += "time * degreesPerTick * ticksPerSecond;";
}
selectedLayer.property("ADBE Transform Group").property("ADBE Rotate Z").expression = effectExpression;
app.endUndoGroup();
alert("已将时钟效果应用于图层:" + selectedLayer.name);
};
scriptWindow.layout.layout(true);
scriptWindow.layout.resize();
scriptWindow.onResizing = scriptWindow.onResize = function () {
this.layout.resize();
};
scriptWindow.center();
scriptWindow.show();
}
if (parseFloat(app.version) < 14) {
alert("该脚本需要 Adobe After Effects CC 2017 或更高版本。");
} else {
SecondHandEffectScript();
}