有没有一种方式可以在Adobe After Effects完成渲染后以编程方式运行shell命令?
您可以使用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
如果您想在另一个窗口中打开命令行,则必须将cmdLineToExecute
设置为像在命令行中一样。
在Windows上,如果您想在另一个窗口中打开命令行,则必须执行以下操作:
start cmd.exe
system.callSystem("cmd.exe /c start cmd.exe ");
这是@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);
};
尝试这段代码。你需要调查的唯一问题是为什么(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);
};