【AE脚本】计算关键帧间隔帧数

原贴:https://www.bilibili.com/read/cv12796485

作者:JoffeeLin

功能:计算关键帧间隔帧

特性:选择多个关键帧时,计算的是头尾两个关键帧的间隔帧数

【AE脚本】计算关键帧间隔帧数
【AE脚本】计算关键帧间隔帧数

//by JoffeeLin 
//link:https://www.bilibili.com/read/cv12796485
var myWindow;
var myPalette = buildUI(this);

if (myPalette != null && myPalette instanceof Window) {
    myPalette.show();
}

function buildUI(thisObject) {
    if (thisObject instanceof Panel) {
        myWindow = thisObject;
    } else {
        myWindow = new Window("window", "窗口",undefined,{resizeable:true}); // 可选参数 dialog palette window
    }

    //创建面板
    myWindow.myPanel = myWindow.add("group"); // 可选参数  panel  group
    myWindow.myPanel.orientation = "column"; // 可选参数 row  column
  myWindow.myPanel.alignment = ['left','left'];
    myWindow.myPanel.alignChildren = ['left','left'];

    //往面板里添加按钮
    //myWindow.myPanel.resultLabel = myWindow.myPanel.add("statictext",[0,0,200,20],"请选择关键帧",{multiline:true});
    myWindow.myPanel.okButton = myWindow.myPanel.add("button",[0,0,200,20]);
    myWindow.myPanel.okButton.text = "w(゚Д゚)w";

    myWindow.layout.layout(true);
    myWindow.layout.resize();
    myWindow.onResizing = myWindow.onRize = function(){this.layout.resize();}

    myWindow.myPanel.okButton.onClick = onPressed
}

function setResult(txt) {
    if (myWindow && myWindow.myPanel && myWindow.myPanel.okButton) {
        //myWindow.myPanel.resultLabel.text = txt
        myWindow.myPanel.okButton.text = txt
    }
}

function onPressed() {

        //参数
    var thisComp = app.project.activeItem;
    var mSp = thisComp.selectedProperties;
    var count = 0;

    // 条件检查
      if (!thisComp || !(thisComp instanceof CompItem)) {
          setResult("没有选中合成")
          return
      } else if (mSp.length < 1) {
          setResult("没有选中属性");
          return
      }

      // 统计
      var count = countKeys(mSp);
      //如果关键帧数量大于2
      if (count >= 2) {
          var maxmin = maxminTime(mSp);
          var z = maxmin.max - maxmin.min;
          setResult((z * thisComp.frameRate).toFixed(1) +"帧")
      }

      // 如果关键帧数量小于2
      if (count < 2) {
          setResult("请选择两个以上关键帧");
      }
    };

//统计所选关键帧个数
function countKeys(sp) {
  var total = null;
    for (i = 0; i < sp.length; i++) {
        if (typeof sp[i].selectedKeys == typeof []) { //判断 是不是 property group
            total += sp[i].selectedKeys.length;
        }
    }
    return total;
}

//所选关键帧的时间最大最小值
function maxminTime(sp) {
    var max = null;
    var min = null;
    for (i = 0; i < sp.length; i++) {
        if (typeof sp[i].selectedKeys == typeof []) {
            for (j = 0; j < sp[i].selectedKeys.length; j++) {
                v = sp[i].selectedKeys[j];
                a = sp[i].keyTime(v);
                if (min === null|| a > max) {
                    max = a;
                }
                if(min === null || min > a ){
                  min =a ;
                }
            }
        }
    }
  return {
    max: max,
    min: min
  };
}

给TA充电
共{{data.count}}人
人已充电
AE开发脚本开发

【AE脚本】深度遍历文件并删除(用于清理磁盘缓存)

2021-8-18 15:37:11

AE开发脚本开发

【AE脚本示例】颜色转换函数 AE颜色 RGB HSL HEX

2021-8-22 14:38:39

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
今日签到
搜索