我在“ setEase”函数中的for循环不会增加“ i”

function storeKeyframes(){
            var properties      = app.project.activeItem.selectedProperties;
            var activeProperty  = null;
            var keySelection    = null;
            var curKey          = null;
            var curKeyTime      = null;
            var curKeyIndex     = null;

            var theEase         = new KeyframeEase(0 , slider_1_slider.value);

            for (var i = 0; i < properties.length; i++){
                activeProperty = properties[i];
                setEase();
            }

            function setEase(){
                for (var i = 0; i < activeProperty.selectedKeys.length ; i++){
                    keySelection    = activeProperty.selectedKeys;
                    curKey          = keySelection[i];
                    curKeyTime      = activeProperty.keyTime(curKey);
                    curKeyIndex     = activeProperty.nearestKeyIndex(curKeyTime);

                    activeProperty.setInterpolationTypeAtKey(curKeyIndex, KeyframeInterpolationType.BEZIER, KeyframeInterpolationType.BEZIER);
                    activeProperty.setTemporalEaseAtKey(curKeyIndex,theEase, theEase);
                }
            }
        }


我只是不知道为什么。我想念什么吗?

最佳答案

我尝试了您的代码,但实际上“ i”并没有增加,但是对我来说,原因是出现了错误。

发生错误的主要原因是setTemporalEaseAtKey()的第二个和第三个参数应该是KeyframeEase的数组,而不仅仅是KeyframeEase(请参见脚本指南)。
另一个原因是activeProperty不必是实际的Property,因此查询activeProperty.selectedKeys.length将引发错误。

附带一提,您所称的curKeyIndex实际上与curKey相同,因此您不需要NearestKeyIndex东西。以下代码对我有用:


function storeKeyframes(){
    var comp = app.project.activeItem;
    if (!comp || comp.typeName !== "Composition") return;
    var properties = comp.selectedProperties;
    var i, I=properties.length;
    var ease1 = new KeyframeEase(0,100);

    for (i=0; i<I; i++){
        if (properties[i] instanceof Property) setEase(properties[i], ease1);
        };
    };
function setEase(property, ease1){
    var ease = property.propertyValueType===PropertyValueType.Two_D ? [ease1, ease1] : (property.propertyValueType===PropertyValueType.Three_D ? [ease1, ease1, ease1] : [ease1]);
    var keySelection = property.selectedKeys;
    var i, I=keySelection.length;
    for (i=0; i<I; i++){
        property.setInterpolationTypeAtKey(keySelection[i], KeyframeInterpolationType.BEZIER, KeyframeInterpolationType.BEZIER);
        property.setTemporalEaseAtKey(keySelection[i], ease, ease);
        };
    };
storeKeyframes();

10-07 17:34