【问题标题】:C++ and Adobe Extend Script (After Effects)C++ 和 Adob​​e Extend Script (After Effects)
【发布时间】:2022-12-16 09:02:31
【问题描述】:

如何从我的 C++ 应用程序中运行 Adob​​e Extend Scripts?如果我打开 After Effects 项目并运行脚本,我有一个工作 JSX 文件可以完成我需要的工作。

我本质上是想在使用 C++ 的 After Effects 项目上调用 JSX 脚本。

我问了 ChatGPT 这个问题(我太现代了),它提到了以下代码:

#include <iostream>
#include "extendscript.h"

int main()
{
    // Create an instance of the ExtendScript object
    ExtendScript script;

    // Load the ExtendScript script file
    if (!script.LoadScriptFile("myscript.jsx"))
    {
        std::cerr << "Failed to load script file" << std::endl;
        return 1;
    }

    // Set the 'this' property of the ExtendScript object to the current After Effects project
    script.SetThisProperty(app.project);

    // Execute the script
    if (!script.EvaluateScript())
    {
        std::cerr << "Failed to evaluate script" << std::endl;
        return 1;
    }

    // Retrieve the project name from the script
    ExtendScriptValue result = script.GetGlobalProperty("projectName");

    // Print the project name
    std::cout << "The project name is: " << result.ToString() << std::endl;

    return 0;
}

这看起来很酷,但我找不到任何与上述 API 调用匹配的在线内容,也找不到任何方法来找到这个难以捉摸的“extendscript.h”文件。

完全有可能是 ChatGPT 编造了这一切并给了我错误的希望。

【问题讨论】:

    标签: c++ adobe extendscript after-effects


    【解决方案1】:

    所以我找到了一些解决方法,即在 C++ 代码中运行两个终端命令,并在第二个命令上执行条件执行 (&&)。

    第一个终端命令打开 .aep 文件:

    open -b com.adobe.AfterEffects --args /Users/ExampleUser/ExampleFolder/TestProject.aep 
    
    

    第二个终端命令(使用 AppleScripts)运行 JSX 文件:

    osascript -l JavaScript -e "ae = Application('Adobe After Effects 2023'); ae.activate(); ae.doscriptfile('/Users/ExampleUser/ExampleFolder/TestScript.jsx');" 
    
    

    所以要从 C++ 内部运行它们:

    #include <iostream>
    int main() {
    
        std::string command = "open -b com.adobe.AfterEffects --args /Users/ExampleUser/ExampleFolder/TestProject.aep && osascript -l JavaScript -e "ae = Application('Adobe After Effects 2023'); ae.activate(); ae.doscriptfile('/Users/ExampleUser/ExampleFolder/TestScript.jsx');"";
    
        system(command.c_str());
        return 0;
    }
    
    

    这会打开 AE 项目,等待操作完成,然后在该项目上运行脚本。

    我相信你还可以添加:

    app.project.close(CloseOptions.SAVE_CHANGES);
    app.quit();
    

    如果您希望 AE 在脚本运行后关闭,请添加到 JSX。

    可能还有一个 --noui 标志可以在某处使用,因此您不需要“看到”它正在打开和运行,但我还没有弄清楚这一点。

    如果有人有更好的解决方案请告诉我!

    【讨论】: