Skip to main content
Participant
October 25, 2022
Answered

Adobe Scripting Bulk Replacing .png Footage

  • October 25, 2022
  • 2 replies
  • 310 views

Hello,

I am trying to write a script to Bulk Replace a lot of png files numerous times and then add them to the media Encoder.

The Projects I will be working with will be quite large so I am hesitant to use indexes for anything. However I just don't know how to get the contents of a project folder inside After effects?

A simplified structure looks like this

- comp

- comp

- folder1

- folder2

-- png 1

-- png 2

-- png 3

 

I want to be able to replace all the .png's with other png's on my system. As stated the system part works fine and is ready to go, but how do I specifically target all the .png's in this folder? Usually in programming languages you can just grab all children of something and loop through them but this doesn't seem to be the case.

So how do I get all elements inside a folder in after effects?
And in the next step do I just have to replace the footage and send it to the media encoder?

 

I have programming experience however this is my first time trying adobe scripting. Any help is gladly appreciated.

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

First you need to go through the project bin and find the folder, then you can go through the project bin again, looking for footage items in that folder, like this:

 

function getFolder(theName){
	for (var i = 1; i <= app.project.numItems; i++){
		if (app.project.item(i) instanceof FolderItem && app.project.item(i).name == theName){
			return app.project.item(i);
		}
	}
	return null;
}

var myFolder = getFolder("Folder 2");
var myFootage = [];
if (myFolder != null){
	for (var i = 1; i <= app.project.numItems; i++){
		if (app.project.item(i) instanceof FootageItem && app.project.item(i).parentFolder.id == myFolder.id){
			myFootage.push(app.project.item(i));
		}
	}
}

alert (myFootage.length);

 

2 replies

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

First you need to go through the project bin and find the folder, then you can go through the project bin again, looking for footage items in that folder, like this:

 

function getFolder(theName){
	for (var i = 1; i <= app.project.numItems; i++){
		if (app.project.item(i) instanceof FolderItem && app.project.item(i).name == theName){
			return app.project.item(i);
		}
	}
	return null;
}

var myFolder = getFolder("Folder 2");
var myFootage = [];
if (myFolder != null){
	for (var i = 1; i <= app.project.numItems; i++){
		if (app.project.item(i) instanceof FootageItem && app.project.item(i).parentFolder.id == myFolder.id){
			myFootage.push(app.project.item(i));
		}
	}
}

alert (myFootage.length);

 

Participant
November 2, 2022

Perfect. thank you!

Mylenium
Legend
October 25, 2022

You can check "is instanceOf AVItem" and the source file with ".isFootage" and similar. Once that's done you can simply resolve the file path and name. Refer to the scripting guide for more details:

 

Welcome to the After Effects Scripting Guide! — After Effects Scripting Guide 22.0.0 documentation

 

You may also want to download soem example scripts from AEScripts.com and learn from the code.

 

Mylenium

Participant
November 2, 2022

Thanks for the hint! I might have been unclear, but this was not the problem I was tryng to solve. I was unaware that a folder item has items() as well that you can loop through this is what I was looking for.
On a side note: I just checked the doc and and it said "attempting to check if item instanceof AVItem will fail because AVItem is undefined. This is also true for Item itself." So you would have to check if it is a FootageItem instead.