2023年12月20日 星期三

[AE腳本] 筆記向: 取得所有效果的變更參數

只要複製內容, 新建一個getAllChangeProperties.jsx 檔案,

然後記事本打開, 貼上進去, 再用ae調用即可 

// 源码: https://www.yuelili.com/?p=22695
// 介绍: 获取当前选择图层所有效果已更改的属性名和数值

// 字符串发送到剪切板
function copyToClipboard(text) {
    var tempFile = new File(Folder.temp.fullName + "/temp.txt");
    tempFile.open("w");
    tempFile.write(text);
    tempFile.close();

    if (Folder.fs === "Windows") {
        var cmdCommand = 'cmd.exe /c cmd.exe /c "type ' + tempFile.fsName + ' | clip"';
        system.callSystem(cmdCommand);
    } else if (Folder.fs === "Macintosh") {
        var osaCommand = 'cat "' + tempFile.fsName + '" | pbcopy';
        system.callSystem("osascript -e '" + osaCommand + "'");
    } else {
        alert("Unsupported operating system.");
    }

    // 删除临时文件
    tempFile.remove();
}

var activeComp = app.project.activeItem;
if (activeComp instanceof CompItem) {
    var selectedLayer = activeComp.selectedLayers[0];
    if (selectedLayer) {
        var effects = selectedLayer.property("ADBE Effect Parade");
        var result = ""

        // 遍历所有效果
        for (var i = 1; i <= effects.numProperties; i++) {
            var effect = effects.property(i);
            // 检查效果是否被更改
            if (effect.isModified) {
                var effectName = effect.name;

                result += "\n\n---\n\n";
                result += "\n" + effectName;

                var numProperties = effect.numProperties;

                // 遍历属性
                for (var j = 1; j <= numProperties; j++) {
                    var property = effect.property(j);
                    // 检查属性是否被更改
                    try {
                        // 加个异常处理 有些自定义属性貌似获取不到
                        if (property.isModified && property.propertyType === PropertyType.PROPERTY && property.propertyValueType !== PropertyValueType.NO_VALUE) {
                            // 获取属性名称和值

                            var propertyName = property.name;
                            var propertyValue = property.value;
                            result += "\n- " + (propertyName + ": " + propertyValue.toString());

                            // 查看是否有表达式
                            if (property.expressionEnabled) {

                                try {
                                    var propertyName = property.name;
                                    var propertyValue = property.expression;
                                    result += "\n" + (propertyName + ": " + propertyValue);
                                } catch (error) {

                                }
                            }
                        }
                    } catch (err) {

                    }
                }
            }
        }
        // 删除开头的\n
        result = result.slice(1)
        // 发送到剪切板
        copyToClipboard(result);
    }
}