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

时间:2016-02-02 01:50:18

标签: shell after-effects

有没有办法在Adobe After Effects中完成渲染后以编程方式运行shell命令?

2 个答案:

答案 0 :(得分:4)

从After Effects

执行命令行

您可以使用sysmte.callSystem(cmdLineToExecute)功能执行命令行。请参阅After Effects Scripting Guide页面 180 部分系统调用系统()方法

这是一个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);
};

答案 1 :(得分: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);
};