Copy link to clipboard
Copied
Hello friends, I am trying to automate a task in our office. I want to move to every layer above in point. At each point it stops, there is a staggered text field that I want to overlay on the frame at that time. I came up with this script but cannot get it to save the Photoshop file. Could someone with experience take a look. Any help or suggestions welcome. Thanks
if (app.project.activeItem != null && app.project.activeItem instanceof CompItem) {
var comp = app.project.activeItem;
var selectedLayers = comp.selectedLayers;
if (selectedLayers.length === 1) {
app.beginUndoGroup("Move Up Through InPoints");
var currentLayer = selectedLayers[0];
var fileIndex = 1; // Start file index
while (currentLayer.index > 1) {
// Get layer above
var layerAbove = comp.layer(currentLayer.index - 1);
// Move playhead to layerAbove's inPoint
comp.time = layerAbove.inPoint;
// Pause for a moment
$.sleep(1500);
// Select layerAbove
currentLayer.selected = false;
layerAbove.selected = true;
// **Automate Save Frame As Photoshop Layers**
var savePath = new File("C:/Temp/Test_" + fileIndex + ".psd");
app.executeCommand(app.findMenuCommandId("Save Frame As"));
app.executeCommand(app.findMenuCommandId("Photoshop Layers"));
// Increment index for unique filenames
fileIndex++;
// Step to next layer up
currentLayer = layerAbove;
}
app.endUndoGroup();
} else {
alert("Please select a single layer.");
}
} else {
alert("Please select a composition first.");
}
I think I'd use the undocumented saveFrameToPng(), like this maybe:
if (app.project.activeItem != null && app.project.activeItem instanceof CompItem) {
var comp = app.project.activeItem;
for (var i = comp.numLayers; i > 0; i--){
var savePath = new File("C:/Temp/Test_" + i + ".png");
comp.saveFrameToPng(comp.layer(i).inPoint,savePath);
$.sleep(500);
}
} else {
alert("Please select a composition first.");
}
EDIT: there was a bug, so I updated it. --DE
Copy link to clipboard
Copied
I don't think your first executeCommand() does anything for you, and the second needs the 3 dots, like this:
app.executeCommand(app.findMenuCommandId("Photoshop Layers..."));
But I think all it will do is pop up the Save As dialog, where you'll have to intervene manually.
Copy link to clipboard
Copied
Hi, I'm really glad to have your input. I do not really need it to go that way. I just want a way to save an image file automatically. I do not want to interact with a dialog. JPEG, PNG or any other type of file will work. If you know any ways to accomplish this, please show me. The script should move to the in point of each layer and save an image file. Thanks for the reply.
Copy link to clipboard
Copied
I think I'd use the undocumented saveFrameToPng(), like this maybe:
if (app.project.activeItem != null && app.project.activeItem instanceof CompItem) {
var comp = app.project.activeItem;
for (var i = comp.numLayers; i > 0; i--){
var savePath = new File("C:/Temp/Test_" + i + ".png");
comp.saveFrameToPng(comp.layer(i).inPoint,savePath);
$.sleep(500);
}
} else {
alert("Please select a composition first.");
}
EDIT: there was a bug, so I updated it. --DE
Copy link to clipboard
Copied
Wow... that is super. It is good to know about what is undocumented. That worked like a cham. Thank you so much!!! People here in this forum like youself are so talented.