Skip to main content
Lucas Greek
Known Participant
October 19, 2022
Answered

Applying a script on multiple compositions

  • October 19, 2022
  • 5 replies
  • 838 views

Hello everyone,

How Can I apply a script .jsx on multiple compositions at once? I do have several compositions within a project but finding them and applying the same script it's time consuming. Is there any way to do it at once or a work-around? Thank You.

This topic has been closed for replies.
Correct answer Dan Ebberts

This would be one way to loop through all comps and combine your two functions:

var myComp, myLayer, myTextLayer, myAudioLayer;
for (var i = 1; i <= app.project.numItems; i++){
	myComp = app.project.item(i);
	if (! (myComp instanceof CompItem)) continue;
	for (var j = 1; j <= myComp.numLayers; j++){
		myLayer = myComp.layer(j);
		if (myLayer.hasAudio){
			myLayer.outPoint = myLayer.inPoint + myLayer.source.duration;
		}
	}
	for (var j = 1; j <= myComp.numLayers; j++){
		myTextLayer = myComp.layer(j);
		if (myTextLayer instanceof TextLayer){
			try{
				myAudioLayer = myComp.layer(myTextLayer.name + ".mp3");
			}catch (err){
				myAudioLayer = null;
			}
			if (myAudioLayer == null) continue;
			myTextLayer.startTime = myAudioLayer.inPoint;
			myTextLayer.outPoint = myAudioLayer.outPoint;
		}
	}
}

5 replies

Mylenium
Legend
October 20, 2022

Register on AEScripts.com, add some free scripts like Rd Comp Setter or the Nab scripts, copy & paste their functions. For copyright reasons we can't just provide the code here.

 

Mylenium 

Lucas Greek
Known Participant
October 20, 2022

Thank you 🙂 

I guess sth like this could help as well, but i'm still exploring the aescrips.com website

function openComps() {
  var comps = [];
  do {
    comps.unshift(app.project.activeItem);
    app.executeCommand(app.findMenuCommandId("Close"));
  } while (app.project.activeItem != null && app.project.activeItem instanceof CompItem);

  for (var i = 0; i < comps.length; i++) {
    comps[i].openInViewer();
  }

  return comps
}

 

 

Lucas Greek
Known Participant
October 20, 2022

is there any other free solution? or at least a tutorial to get close to the solution?

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
October 20, 2022

This would be one way to loop through all comps and combine your two functions:

var myComp, myLayer, myTextLayer, myAudioLayer;
for (var i = 1; i <= app.project.numItems; i++){
	myComp = app.project.item(i);
	if (! (myComp instanceof CompItem)) continue;
	for (var j = 1; j <= myComp.numLayers; j++){
		myLayer = myComp.layer(j);
		if (myLayer.hasAudio){
			myLayer.outPoint = myLayer.inPoint + myLayer.source.duration;
		}
	}
	for (var j = 1; j <= myComp.numLayers; j++){
		myTextLayer = myComp.layer(j);
		if (myTextLayer instanceof TextLayer){
			try{
				myAudioLayer = myComp.layer(myTextLayer.name + ".mp3");
			}catch (err){
				myAudioLayer = null;
			}
			if (myAudioLayer == null) continue;
			myTextLayer.startTime = myAudioLayer.inPoint;
			myTextLayer.outPoint = myAudioLayer.outPoint;
		}
	}
}
Lucas Greek
Known Participant
October 20, 2022

Thank you so much Dan Ebberts,

This one works like a charm! Exactly What I needed 🙂

Mylenium
Legend
October 19, 2022

The respecetive loop is part of pretty much any script that does project-wide changes, so you can just snatch it from an existing script and adjust your variables. A short excursion to AEScripts.com and downloading one of those bulk composition chnaging tools can show you how it's done You basically define a variable with myItems=app.project.items and then do a for(i=0;i>=myItems.length;i++) loop and then check each active item. This can be super fancy with item type checks or just quick & dirty.

 

Mylenium

Mathias Moehl
Community Expert
Community Expert
October 19, 2022

In a nutshell, instead of

var myComp = app.project.activeItem;

 you need to put your code inside a loop which iterates over all compositions, and then assign myComp to a different comp in each iteration.

There is no direct way to access the list of all compositions in the scripting API. Instead, you need to loop over all project items and then check for all of them, if they are compositions.

Note that my extension Automation Blocks allows to create scripts in a simpler, visual way. There you would use the "for each project item" block to loop over all comps and the simply plug and code blocks inside of it, which should be executed for all these comps.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Mylenium
Legend
October 19, 2022

That functionality can be built into the script itself by letting it comb through all project items, but without knowing what script you use and what you expect it to do nobody can tel lyou much. As always the devil's in teh details.

 

Mylenium

Lucas Greek
Known Participant
October 19, 2022

So I'm using two sctipts. One of them is this one:

var myComp = app.project.activeItem;
var myLayer;
for (var i = 1; i <= myComp.numLayers; i++){
	myLayer = myComp.layer(i);
	if (! myLayer.hasAudio) continue;
	myLayer.outPoint = myLayer.inPoint + myLayer.source.duration;
}

 

and the second: 

 

	function adjustText(){
	var myComp = app.project.activeItem;
	if (myComp == null || ! (myComp instanceof CompItem)){
		alert ("No comp active.");
		return;
	}
	var myTextLayer;
	var myAudioLayer;
	for (var i = 1; i <= myComp.numLayers; i++){
		if (myComp.layer(i) instanceof TextLayer){
			myTextLayer = myComp.layer(i);
			try{
				myAudioLayer = myComp.layer(myTextLayer.name + ".mp3");
			}catch (err){
				myAudioLayer = null;
			}
			if (myAudioLayer == null) continue;
			myTextLayer.startTime = myAudioLayer.inPoint;
			myTextLayer.outPoint = myAudioLayer.outPoint;
		}
	}

}
adjustText();

 

Do you got any advice how to make it happen? Or where should I start looking for this solution? Thank you.