Skip to main content
Known Participant
April 14, 2021
解決済み

Ae scripting saveFrameAsPng() set to save to project location

  • April 14, 2021
  • 返信数 1.
  • 717 ビュー

Hello, I am wondering if is it possible via scripting, using the saveFrameAsPng() function, to automatically save to the same folder as the opened project file. Hoenstly, I tried to do this already and just as I ran the script, a bunch of my files and folders just dissapeared (thank god we have RAIDed clones drives). It was a major mistake to learn from, I won't post my code but to give oyu an idea of how I was going about it,  

 
in the save location atribute of saveFramAsPng() function I had a variable projfolder
var projFolder = app.project.file.parent;
 
If anyone has any suggesitons on how to make the saveFrameAsPng() function save to the current projects folder it would be greatly appreciated. thank you.
このトピックへの返信は締め切られました。
解決に役立った回答 Paul Tuersley

Despite never replying or marking answers correct when I help you out, I'll give you another chance as I'm feeling generous today!

 

It sounds like you were feeding the folder containing your project into the save location so it was overwriting the folder with a PNG of the same name. You do need to be careful when messing around in your file system using scripts.

 

You just need to add a file name for the png onto the file path for the project folder. In this example I've derived it from the comp name but you can name it however you like.

var activeItem = app.project.activeItem;

if (activeItem != null && activeItem instanceof CompItem) {
	var PNGfile = new File(app.project.file.parent.absoluteURI + "/" + activeItem.name + ".png");
	
	// if file doesn't already exist or user confirms it's ok to overwrite....
	if (!PNGfile.exists || confirm(File.decode(PNGfile.absoluteURI) + " exists. Overwrite?")) {
		activeItem.saveFrameToPng(0, PNGfile);
	}

}

返信数 1

Paul Tuersley解決!
Inspiring
April 14, 2021

Despite never replying or marking answers correct when I help you out, I'll give you another chance as I'm feeling generous today!

 

It sounds like you were feeding the folder containing your project into the save location so it was overwriting the folder with a PNG of the same name. You do need to be careful when messing around in your file system using scripts.

 

You just need to add a file name for the png onto the file path for the project folder. In this example I've derived it from the comp name but you can name it however you like.

var activeItem = app.project.activeItem;

if (activeItem != null && activeItem instanceof CompItem) {
	var PNGfile = new File(app.project.file.parent.absoluteURI + "/" + activeItem.name + ".png");
	
	// if file doesn't already exist or user confirms it's ok to overwrite....
	if (!PNGfile.exists || confirm(File.decode(PNGfile.absoluteURI) + " exists. Overwrite?")) {
		activeItem.saveFrameToPng(0, PNGfile);
	}

}
mattg83667320作成者
Known Participant
April 14, 2021

Thank you Paul for helping me out with this problem. Writing this short series of scripts for my team is my pet project away from the busy editing bay, so I apologize if I havent compeltely followed forum ettiquette. But I will say that your answers are always helpful. I've learned a lot since starting this scripting journey, due in no small part to your input with some of these begginer hurdles and seeing where my I need to recalculate my assumptions about how some of this works This answer is no exception, its clear and reads to me like a sentence and gives me some exposure to some commands and methods I have not yet explored (and will do so carefully). Thank you for your reply.