Activity › Forums › Adobe After Effects Expressions › Need somebody to develop a scrip to change comp length
-
Need somebody to develop a scrip to change comp length
-
Luca Rechsteiner
January 17, 2023 at 10:49 pmHello does it exist a script to change comp length depending the length of characters of a text? If I understand right there is no expression that can handle that and I need a script. I would like to know if somebody can help me in developing this.
I would have different compositions with different sentences. I would like the length of the composition be longer with longer texts and shorter with shorter texts. Also I would like to have a fade to black at the beginning/end and also the music to fade out at the end of the comp. Does this make sense? Does somebody I can also pay want to help me developing this script?
Thanks a lot
Luca
-
Jace Bradley
January 18, 2023 at 1:46 amThere’s a free script that changes the comp length based on different parameters. The script is called zl.TrimCompToContents
-
Andrei Popa
January 18, 2023 at 7:56 amIt’s possible to make the comp length proportionally to the length of a text (I assume you want to count characters). The 2 are also possible, but you need to be more specific. Do you want some layers inside the comp to fade? Or the comp, somewhere where it is used as a layer.
Here is a snippet that modifies the length of the current comp according to the number of characters in the first text layer.
function setCompLength(myComp, framesPerChar) {
//search first text layer and save character number
for (var i = 1; i <= myComp.numLayers; i++) {
var crtLayer = myComp.layer(i);
if (crtLayer instanceof TextLayer) {
var numChars = crtLayer.text.sourceText.value.text.length;
break;
}
}
myComp.duration = framesPerChar * myComp.frameDuration * numChars;
}
setCompLength(app.project.activeItem, 10); -
Luca Rechsteiner
January 18, 2023 at 9:59 amHi. First, thanks a lot for your answers. I am really new to scripts so it is very precious!
For length script, where do I manage the length/number of characters? Imagine I want 1 second each 10 characters.
Regarding point 2, I need one or more layers to fade to black so I assume we can play a little with opacity? I also need the music to fade out to silence at the end of the comp…
How to implement this to the script?
Thanks a LOT!!!
-
Andrei Popa
January 18, 2023 at 11:37 amIn the last line, 10 is how many frames you want per char. 10 chars for 1 seconds in 30 fps would be 3.
Here are 3 functions that should help you out. You can modify the options object (everything that is between {}) to your needs.
var options = {
fadeToBlackLayerIndex: 2,
fadeOutSoundLayerIndex: 4,
duration: 1,
comp: app.project.activeItem,
framesPerChar:3
};
app.beginUndoGroup("modify composition");
setCompLength(options);
fadeToBlack(options);
fadeOutSound(options);
app.endUndoGroup();
function fadeToBlack(options) {
var comp = options.comp;
var duration = options.duration;
var layerIndex = options.fadeToBlackLayerIndex;
var layer = comp.layer(layerIndex);
layer.opacity.setValueAtTime(comp.duration - duration, layer.opacity.valueAtTime(comp.duration - duration, false));
layer.opacity.setValueAtTime(comp.duration, 0);
}
function fadeOutSound(options) {
var layerIndex = options.fadeOutSoundLayerIndex;
var comp = options.comp;
var duration = options.duration;
var layer = comp.layer(layerIndex);
layer.audio.audioLevels.setValueAtTime(comp.duration - duration, layer.audio.audioLevels.valueAtTime(comp.duration - duration, false));
layer.audio.audioLevels.setValueAtTime(comp.duration, [-40, -40]);
}
function setCompLength(options) {
var myComp = options.comp;
var framesPerChar = options.framesPerChar;
//search first text layer and save character number
for (var i = 1; i <= myComp.numLayers; i++) {
var crtLayer = myComp.layer(i);
if (crtLayer instanceof TextLayer) {
var numChars = crtLayer.text.sourceText.value.text.length;
break;
}
}
myComp.duration = framesPerChar * myComp.frameDuration * numChars;
} -
Luca Rechsteiner
January 26, 2023 at 2:00 pmHello Andrei, I applied just the first scritp and it works but when I applay the second long one I have an error message: that I join to this post. I would like to see if you can help me in developing something, how can I discuss with you? Thanks Luca
Reply to this Discussion! Login or Sign Up
Log in to reply.