FORUMS: list search recent posts

Script that changes the duration of some compositions and arrange them on timeline

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Nuria Sanchez
Script that changes the duration of some compositions and arrange them on timeline
on Feb 25, 2016 at 5:51:45 pm

Hello,
a couple of mounths ago i have dicoverd After Effects and i started learn to work with it, but now i am stuck with my new project, becouse my scripting and expressions skills are almost 0.

The project looks like this Project screenshot,and it has:
3 audio files named audio 1.wav, audio 2.wav, audio 3.wav
3 compositions named Song 1, Song 2, Song 3 wich include each one the coresponding audio file
1 composition named Render Comp which include the 3 Song compositions.

My intention is to create some kind of template, becouse i will have to render
some videos with different audio files.

My question is: is it posible to create a script which:

1. on click changes the duration of each "Song" composition using the length of its corresponding audio file
2. arrange the "Song" compositions one after each other in the Render Comp, and cut the Render Comp duration at the end of Song 3 composition?

If is possible, can i have a little help with the code please, if is not too much, because i am quite new in scripting and i don't have any idea how to do it. Thanks in advance


Return to posts index

Nuria Sanchez
Re: Script that changes the duration of some compositions and arrange them on timeline
on Feb 26, 2016 at 12:51:39 am

For the second point i have created a script already and it is working...i only need help with the script for the first part please


Return to posts index

Miguel de Mendoza
Re: Script that changes the duration of some compositions and arrange them on timeline
on Feb 26, 2016 at 2:02:52 am

Is there any reason you want to do it through a script?

According to the screenshot you've uploaded, you can do it by simply dragging the audio tracks from your project panel on the Create comp icon, or by right click on the tracks and click on "Create comps from selection"


Return to posts index


Nuria Sanchez
Re: Script that changes the duration of some compositions and arrange them on timeline
on Feb 26, 2016 at 9:39:58 am

The composition will be much more complex...will have maybe 20 audio files, and different other footages...so changing this stuff manually each time when i do a video like this is very time consuming....do you think that can be done with the help of a script?


Return to posts index

Miguel de Mendoza
Re: Script that changes the duration of some compositions and arrange them on timeline
on Feb 26, 2016 at 11:33:45 am

Yes, it can be done by many ways. The key is to stablish a way to find the correct layer on each comp. Let' say that you always have your song in the last layer of each comp, you can do this:

var proj = app.project;

function chageCompsDuration() {
var selectedComps = proj.selection;
if(selectedComps.length == 0) {
alert("Select one or more comps");
}

for (var i = 0; i < selectedComps.length; i++){
var curComp = selectedComps[i];
var layerIndex = curComp.layers.length; //change this for other search type
var audioLayer = curComp.layer(layerIndex);

if( audioLayer.hasAudio == false || audioLayer.hasVideo == true) {
alert("Layer" + audioLayer.name + "in Comp" + curComp.name + "is not an audio file");
}

curComp.duration = audioLayer.source.duration;
}
}

chageCompsDuration()


Then you only have to select the comps you want to change and run the script (or use the function in a onClick event, anywhere you want).


Return to posts index

Nuria Sanchez
Re: Script that changes the duration of some compositions and arrange them on timeline
on Feb 26, 2016 at 2:21:10 pm

Thanks for helping me, the code seems not to work with my project...the one that i have attatched, it gives a error at line 12:

var audioLayer = curComp.layer(layerIndex);

i have selected all 3 compositions 'Song 1' 'Song 2' and 'Song 3' together, i have tryed with each one individual and nothing...same error..


Return to posts index


Miguel de Mendoza
Re: Script that changes the duration of some compositions and arrange them on timeline
on Feb 27, 2016 at 4:46:49 pm

Can you write the full error code?


Return to posts index

Nuria Sanchez
Re: Script that changes the duration of some compositions and arrange them on timeline
on Mar 2, 2016 at 1:15:44 pm

Well it does not say anything...it stops and the 12 line is in red...

Anyway, i manage to do what i needed using a script, but i have to take all the comps one by one...it is not a big problem...

Thanks for trying to help me.


Return to posts index

Avinash Ramanath
Re: Script that changes the duration of some compositions and arrange them on timeline
on Apr 21, 2017 at 7:40:30 pm

Try This

for example:
var audioLayer = curComp.layer(2); this means the layer number of your audio file is 2


Return to posts index


Avinash Ramanath
Re: Script that changes the duration of some compositions and arrange them on timeline
on Apr 26, 2017 at 7:02:09 am

" For the second point i have created a script already and it is working...i only need help with the script for the first part please "
Can you please share that script with me. It will be a huge help.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]