how to control ram preview through scripting
I am currently working on developing a CEP extension for After Effects. I have implemented a function aimed at controlling the opacity of selected layers and creating keyframes at the current time. The function works well, depending on the opacity value received from a slider. Here is the current implementation:
function controlOpacity(opacityValue) {
app.beginUndoGroup("Opacity Change");
var layer = null;
var newOpacity = null;
var comp = app.project.activeItem;
if (comp !== null && comp instanceof CompItem) {
var selectedLayers = comp.selectedLayers;
if (selectedLayers.length > 0) {
var currentTime = comp.time;
for (var i = 0; i < selectedLayers.length; i++) {
layer = selectedLayers[i];
newOpacity = opacityValue;
layer.property("Opacity").setValueAtTime(currentTime, newOpacity);
}
}
}
app.endUndoGroup();
}
The issue is:
While dragging the slider, the function updates the timeline RAM preview continuously, causing excessive RAM usage. Consequently, the green bar for the RAM preview keeps updating simultaneously, leading to high memory consumption.
Analysis:
Upon observation, I noticed that in After Effects, when dragging the opacity property value, the composition panel preview updates without affecting the timeline. The green bar for RAM preview appears only upon releasing the mouse button.
My question is:
Can i replicate this behavior in my extension?
