gpt4 book ai didi

javascript - Adobe ExtendScript 中的 For 循环

转载 作者:行者123 更新时间:2023-12-03 07:54:52 24 4
gpt4 key购买 nike

“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();

关于javascript - Adobe ExtendScript 中的 For 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34844849/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com