渲染完成后运行shell命令(After Effects)

3
有没有一种方式可以在Adobe After Effects完成渲染后以编程方式运行shell命令?

在Windows上?在Mac上?你试过什么了吗? - oktomus
2个回答

4

从After Effects执行命令行

您可以使用system.callSystem(cmdLineToExecute)函数执行命令行。请查看After Effects脚本指南,第180页的System callSystem()方法

这里是一个示例,使用echo命令:(callSystem返回命令行的返回值):

var commandOutput = system.callSystem("cmd.exe /c echo hi ");
alert(commandOutput);

这会输出:

/c后面的是要在cmd中执行的命令。

脚本指南中的一个更复杂的例子,用于获取系统时间:

var timeStr = system.callSystem("cmd.exe /c \"time /t\"");
alert("Current time is " + timeStr);

这将输出:

当前时间为11:28

从After Effects打开命令行

如果您想在另一个窗口中打开命令行,则必须将cmdLineToExecute设置为像在命令行中一样。

在Windows上,如果您想在另一个窗口中打开命令行,则必须执行以下操作:

start cmd.exe

所以,如果你想从 After 中进行操作。
system.callSystem("cmd.exe /c start cmd.exe ");

在After Effects渲染完成后打开命令行

这是@fabiantheblind答案的混合。

// Create a comp with a solid
var comp = app.project.items.addComp('test', 100, 100, 1, 1, 12);
comp.layers.addSolid([0.5, 0.5, 0.5], 'solid', 100, 100, 1, 1);
// Add the comp to the render queue
var rq_item = app.project.renderQueue.items.add(comp);
rq_item.outputModule(1).file = File('~/Desktop/out.mov');
rq_item.render = true;
// Set a function which will be called every frame when the comp will be rendering
// A boolean to be sure that the function called at the end is called once
var called = false;
rq_item.onStatusChanged = function() {
  while (rq_item.status === RQItemStatus.RENDERING) {
    // Is rendering...
    $.writeln('Rendering');

  }

  // When the render is finished
  if (!called && rq_item.status === RQItemStatus.DONE) {
    called = true;
    system.callSystem("cmd.exe /c start cmd.exe ");
  }

};
// Launch the render
app.project.renderQueue.render();

// If something goes wrong
app.onError = function(err) {
  $.writeln('ERROR ' + err);
};

2

尝试这段代码。你需要调查的唯一问题是为什么(rq_item.status === RQItemStatus.DONE)会被调用两次。

// Create a comp with a solid
var comp = app.project.items.addComp('test', 100, 100, 1, 1, 12);
comp.layers.addSolid([0.5, 0.5, 0.5], 'solid', 100, 100, 1, 1);
// Add the comp to the render queue
var rq_item = app.project.renderQueue.items.add(comp);
rq_item.outputModule(1).file = File('~/Desktop/out.mov');
rq_item.render = true;
// Set a function which will be called every frame when the comp will be rendering
// A boolean to be sure that the function called at the end is called once
var called = false;
rq_item.onStatusChanged = function() {
  while (rq_item.status === RQItemStatus.RENDERING) {
    // Is rendering...
    $.writeln('Rendering');

  }

  // When the render is finished
  if (!called && rq_item.status === RQItemStatus.DONE) {
    called = true;
    $.writeln('Done rendering');
    // test for Mac or Win
    var res = null;
    if($.os.charAt (0) === 'M'){
      res = system.callSystem('echo "Hello Mac World"');
    }else{
      res = system.callSystem('cmd.exe /c echo "Hello Win World"');
    }
    $.writeln(res);
  }

};
// Launch the render
app.project.renderQueue.render();

// If something goes wrong
app.onError = function(err) {
  $.writeln('ERROR ' + err);
};

@Kevin。不是吗?当我运行它时,它被调用了两次。顺便说一句,感谢您的编辑。我有点懒得写注释。 :-) - fabianmoronzirfas
很奇怪,这一定是同步问题。为了解决它,你可以将该函数创建一个布尔值,并在第一次渲染完成时将其设置为true。 - oktomus

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接