曼春满村
传统村落系列——曼春满
2020年9月14日
显示全部

影视制作中AE脚本常用操作代码

视频制作脚本

ae脚本

常用操作代码

1. 判断激活和选中

    function selComp() {
        currentComp = app.project.activeItem;
        if (currentComp instanceof CompItem) {
            return true;
        } else {
            alert("没有选中合成");
            return false;
        }
    }

其中
compItem:合成
footageItem:素材(视频音频等)
folderItem:文件夹
layer(s):层
item(s):项目
根据判断目标自行替换

2. 设置工程色深

//设置工程色深(8,16,32)位
app.project.bitsPerChannel = 32;   

3. 设置叠加模式

layer.blendingMode = BlendingMode.COLOR;

1,在AE中创建文件夹:

app.project.items.addFolder("myFolder");

2,判断文件夹是否存在:

function judgeLayer(layername) {
      for(var i = 1; i <= app.project.numItems; i++) {
         if(app.project.item(i).name == layername)
         {
             return false;
         }
     }
     return true;
 };

3,找到一个文件夹对象:

function findFolderItemByName(name){
           var found = false;
           for (i = 1; i <= app.project.numItems; i++){
               if (app.project.item(i).name == name && app.project.item(i) instanceof FolderItem ){
                   var myFolder = app.project.item(i);                   found = myFolder;
                   break
                   }
               }
           return found;
   }

4,,把文件或者文件夹放入一个父级文件夹中:

childFolder.parentFolder = findFolderItemByName("parentFolderName");

5,获取电脑中某个文件夹中的内容:

var folderObj = new Folder("folderPath");
var moveFileList = folderObj.getFiles();

6,导入序列文件到AE中:

var io = new ImportOptions(); 
io.file = new File("filePath"); 
io.sequence = true;
io.forceAlphabetical = true;
mySeq = app.project.importFile(io);
myDuration = mySeq.duration;
<span style="font-family: Arial, Helvetica, sans-serif;"> </span>
<span style="font-family: Arial, Helvetica, sans-serif;"> </span>

myDuration参数表示导入的帧数

7,新建Comp:

var myComp = app.project.items.addComp("testComp", 1920, 1080, 1, 150/25, 25);

这里的150/25表示的是,总共150帧,因为addComp函数接受的参数的单位是秒。

8,设置Comp的起始时间:

myComp.displayStartTime = 2/25;

这里是设置起始帧为1

9,合成中加Layer:

myComp.layers.add(myLayer);

10,设置Comp中某层的某属性:

Comp.layer(1).Scale.setValue([10,10]);
Comp.layers.byName("test").Scale.setValue([10,10]);

11,将Comp中某层移到最下:

myComp.layers.byName("test").moveToEnd();

12,设置某层的时间:

var nowF = (inComp.layer(1).outPoint - inComp.layer(1).inPoint); 
var tarF = timeDuration; var stretchValue = 100*tarF/nowF; inComp.layer(1).stretch = stretchValue;

13,设置某层的matte

lay.trackMatteType = TrackMatteType.ALPHA;
lay.trackMatteType = TrackMatteType.ALPHA_INVERTED
lay.trackMatteType = TrackMatteType.LUMA
lay.trackMatteType = TrackMatteType.LUMA_INVERTED
lay.trackMatteType = TrackMatteType.NO_TRACK_MATTE

14,给某层加特效

myLayer.Effects.addProperty("Roughen Edges")("Border").setValue(0);
myLayer("Effects")("Roughen Edges")("Scale").setValue(170);

15,加solid层

mySolidLayer = timeCodeComp.layers.addSolid([0,0,0],"solid",1920,1080,1,80/25);

16,给solid层加矩形mask

newMask = mySolidLayer.Masks.addProperty("ADBE Mask Atom");
newMask.maskMode = MaskMode.ADD; newMask.color = [1,1,0]; 
myProperty = newMask.property("ADBE Mask Shape"); 
myShape = myProperty.value; 
myShape.vertices = [[600, 70], [600,164], [38,164],[38,70]];
myShape.closed = true;  
myProperty.setValue(myShape);

17,创建层

//空对象
var myNull=currentComp.layers.addNull();
myNull.name="空对象";
//形状层
currentComp.layers.addShape();
// 添加摄像机,addCamera(摄像机名,摄像机中心点位置)
currentComp.layers.addCamera("摄像机",[currentComp.width,currentComp.height]/2);
// 添加灯光层,addLight(灯光名称,灯光中心点位置)
currentComp.layers.addLight("灯光",[currentComp.width,currentComp.height]/2);
currentComp.layers.addSolid([0,1,0],"固态层",currentComp.width,currentComp.height,currentComp.pixelAspect,currentComp.duration);
// 调节层其实就是打开调节开关的固态层
var myAdj=currentComp.layers.addSolid([1,1,1],"调节层",currentComp.width,currentComp.height,currentComp.pixelAspect,currentComp.duration);
//添加文字层,addSolid(颜色,图层名字,宽度,高度,像素长宽比,时长)
newText = new TextDocument("test"); 
var theTextLayer = timeCodeComp.layers.addText(newText); 
theTextLayer.Position.setValue([163,143]); 
var textProp = theTextLayer.property("Source Text"); 
var textDocument = textProp.value; 
textDocument.fontSize=59; 
textDocument.font = "Microsoft YaHei"; 
textDocument.justification = ParagraphJustification.CENTER_JUSTIFY;
textProp.setValue(textDocument);

18,激活某个comp

myComp.openInViewer();

19,关键帧相关操作

thisComp.layer(“xx”).transform.position.key(1).value[0];
thisComp.layer(“xx”).transform.position.key(2).time-l.key(1).time;

//取关键帧值和时间

20,关键帧相关操作

Layer.effect(“Dots “)(1).valueAtTime( time + AV_controllerLayer.inPoint );
}catch(e){ value }

//取标记点时间

评论关闭了。