Skip to main content
Inspiring
May 25, 2020
Answered

Easy way to change duration/framerate to a comp and all contents

  • May 25, 2020
  • 2 replies
  • 971 views

Is there any easy way to change the duration/framerate of a comp and all its contents? 

 

Example

 

I've made a comp (A) that is 30 seconds long 30fps since making that I've made a new comp (B) that is 5 seconds 60fps now the default is this. If I then import a file.

newFile.importAs = ImportAsType.COMP_CROPPED_LAYERS;
newLayer = app.project.importFile(newFile);

into my comp A it will take the settings from comp B.

 

What I've tried

 

In my script I made a throwaway comp that copies the settings from the comp I'm importing to

app.project.items.addComp(mainCompName, mainCompWidth, mainCompHeight, 1, mainCompDuration, mainCompFrameRate);

in hope that it would then change the comp settings defaults for when I import the file. It does not.

 

Another thing I've tried is manually setting the comps duration and then for loop through all the layers to change the outpoints however if there is another comp in this comp I will have to have nesting loops which is fine but I wanted to know if there's an easier way before I write this loop.

 

newLayer.duration = mainCompDuration;
newLayer.frameRate = mainCompFrameRate;

for(i = 1; i <= newLayer.layers.length; i++){
        newLayer.layers[i].outPoint  = mainCompDuration;
    }

Thank you for any help.

This topic has been closed for replies.
Correct answer gregoryw80731704

If anyone else comes across wanting to do something like this, this is the loop I used. There might be an easier way but I can't find it.

//What Comp
newComp = app.project.items[int];

//Run Function
changeDuration(newComp);

function changeDuration(compToChange){
    //Change Comp duration and framerate
    compToChange.duration = mainCompDuration;
    compToChange.frameRate = mainCompFrameRate;
    
             //Change layers outpoint
             for(var i = 1; i <= compToChange.layers.length; i++){
                compToChange.layers[i].outPoint  = mainCompDuration;
                //If layer is a comp restart the loop with that comp
                if(compToChange.layers[i].source.typeName != "Composition"){
                    
                    
        }else changeDuration(compToChange.layers[i].source);
    } 
}

 

2 replies

gregoryw80731704AuthorCorrect answer
Inspiring
May 25, 2020

If anyone else comes across wanting to do something like this, this is the loop I used. There might be an easier way but I can't find it.

//What Comp
newComp = app.project.items[int];

//Run Function
changeDuration(newComp);

function changeDuration(compToChange){
    //Change Comp duration and framerate
    compToChange.duration = mainCompDuration;
    compToChange.frameRate = mainCompFrameRate;
    
             //Change layers outpoint
             for(var i = 1; i <= compToChange.layers.length; i++){
                compToChange.layers[i].outPoint  = mainCompDuration;
                //If layer is a comp restart the loop with that comp
                if(compToChange.layers[i].source.typeName != "Composition"){
                    
                    
        }else changeDuration(compToChange.layers[i].source);
    } 
}

 

Mylenium
Legend
May 25, 2020

Why not simply buy/ download one of the gazillion existing comp changer scripts from AEScripts.com? Typically the issue with nested comp is simply avoided/ resolved by basing any processing on selections, anyway. No need to reinvent the wheel.

 

Mylenium

Inspiring
May 25, 2020

I'm writing my own script to do other things and this was something I ran into whilst writing it. When I pass the scipt on to my team members I don't want them to also have to download more scripts with something I can easily write, just wondered if there was an easier way than a nested loop.