Last active
June 3, 2024 11:28
-
-
Save msongz/bc6ad1e8a69b6b390af745459da2bd47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Mon Jun 3 17:57:26 CST 2024 | |
(function main(thisObj){ | |
// 创建脚本UI面板 | |
function createUI(thisObj) { | |
var panel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "Keyframe Counter", undefined, { resizeable: true }); | |
panel.orientation = "column"; | |
panel.alignChildren = ["fill", "top"]; | |
var button = panel.add("button", undefined, "Count Keyframes"); | |
var textGroup = panel.add("group"); | |
var keyframeLabel = textGroup.add("statictext", undefined, "Total Keyframes: "); | |
var keyframeTextBox = textGroup.add("statictext", undefined, "0"); | |
keyframeTextBox.characters = 10; | |
keyframeTextBox.alignment = ["fill", "fill"]; | |
var compGroup = panel.add("group"); | |
var compLabel = compGroup.add("statictext", undefined, "Total Compositions: "); | |
var compTextBox = compGroup.add("statictext", undefined, "0"); | |
compTextBox.characters = 10; | |
compTextBox.alignment = ["fill", "fill"]; | |
var layerGroup = panel.add("group"); | |
var layerLabel = layerGroup.add("statictext", undefined, "Total Layers: "); | |
var layerTextBox = layerGroup.add("statictext", undefined, "0"); | |
layerTextBox.characters = 10; | |
layerTextBox.alignment = ["fill", "fill"]; | |
// 设置关键帧数字的颜色为黄色 | |
if (keyframeTextBox.graphics) { | |
var yellowColor = [1, 1, 0]; // RGB值表示黄色 | |
keyframeTextBox.graphics.foregroundColor = keyframeTextBox.graphics.newPen(keyframeTextBox.graphics.PenType.SOLID_COLOR, yellowColor, 1); | |
} | |
// 设置开发者名字的颜色为灰色 | |
var developerTextBox = textGroup.add("statictext", undefined, "@微型柠檬"); | |
developerTextBox.alignment = ["right", "fill"]; | |
if (developerTextBox.graphics) { | |
var greyColor = [.2, .2, .2]; // RGB值表示灰色 | |
developerTextBox.graphics.foregroundColor = developerTextBox.graphics.newPen(developerTextBox.graphics.PenType.SOLID_COLOR, greyColor, 1); | |
} | |
button.onClick = function() { | |
var temp = this.text; | |
this.text = "♦︎♦︎♦︎♦︎♦︎"; | |
refreshData(); | |
this.text = temp; | |
this.active = true; | |
this.active = false; | |
}; | |
// 添加点击事件监听器,将关键帧数字归零 | |
keyframeTextBox.addEventListener("click", function() { | |
this.text = "0"; | |
}); | |
panel.onResizing = panel.onResize = function () { | |
this.layout.resize(); | |
this.layout.layout(true); | |
}; | |
if (panel instanceof Window) { | |
panel.center(); | |
panel.show(); | |
} | |
// 设置面板的最小宽度 | |
panel.minimumSize = [350, 0]; | |
panel.layout.layout(true); | |
return panel; | |
} | |
// 定义刷新数据的函数 | |
function refreshData() { | |
var projectData = countProjectData(app.project.rootFolder); | |
if (myScriptPanel) { | |
myScriptPanel.children[1].children[1].text = projectData.totalKeyframes; | |
myScriptPanel.children[2].children[1].text = projectData.totalCompositions; | |
myScriptPanel.children[3].children[1].text = projectData.totalLayers; | |
} | |
} | |
// 创建一个函数来递归统计给定属性中的关键帧数量 | |
function countKeyframesInProperty(property) { | |
var keyframeCount = 0; | |
if (property.numProperties !== undefined) { | |
// 如果属性是一个属性组,递归统计其子属性中的关键帧数量 | |
for (var i = 1; i <= property.numProperties; i++) { | |
keyframeCount += countKeyframesInProperty(property.property(i)); | |
} | |
} else { | |
// 如果属性有关键帧,则直接统计关键帧数量 | |
if (property.numKeys !== undefined && property.numKeys > 0) { | |
keyframeCount += property.numKeys; | |
} | |
} | |
return keyframeCount; | |
} | |
// 创建一个函数来统计图层中的所有关键帧数量 | |
function countKeyframesInLayer(layer) { | |
var keyframeCount = 0; | |
for (var i = 1; i <= layer.numProperties; i++) { | |
keyframeCount += countKeyframesInProperty(layer.property(i)); | |
} | |
return keyframeCount; | |
} | |
// 创建一个函数来统计合成中的所有关键帧和图层数量 | |
function countDataInComp(comp) { | |
var keyframeCount = 0; | |
var layerCount = comp.numLayers; | |
for (var i = 1; i <= comp.numLayers; i++) { | |
keyframeCount += countKeyframesInLayer(comp.layer(i)); | |
} | |
return { | |
keyframes: keyframeCount, | |
layers: layerCount | |
}; | |
} | |
// 创建一个函数来递归统计文件夹中的所有合成的关键帧总数和总图层数 | |
function countProjectData(folder) { | |
var totalKeyframes = 0; | |
var totalLayers = 0; | |
var totalCompositions = 0; | |
for (var i = 1; i <= folder.numItems; i++) { | |
var item = folder.item(i); | |
if (item instanceof CompItem) { | |
totalCompositions++; | |
var compData = countDataInComp(item); | |
totalKeyframes += compData.keyframes; | |
totalLayers += compData.layers; | |
} else if (item instanceof FolderItem) { | |
var folderData = countProjectData(item); | |
totalKeyframes += folderData.totalKeyframes; | |
totalLayers += folderData.totalLayers; | |
totalCompositions += folderData.totalCompositions; | |
} | |
} | |
return { | |
totalKeyframes: totalKeyframes, | |
totalCompositions: totalCompositions, | |
totalLayers: totalLayers | |
}; | |
} | |
// 在After Effects中创建UI面板 | |
var myScriptPanel = createUI(thisObj); | |
})(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment