Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Script, move to layer above, save PSD

Explorer ,
Apr 08, 2025 Apr 08, 2025

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.");
}

 

TOPICS
Expressions , How to , Scripting
201
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 09, 2025 Apr 09, 2025

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

 

Translate
Community Expert ,
Apr 08, 2025 Apr 08, 2025

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.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 09, 2025 Apr 09, 2025

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 09, 2025 Apr 09, 2025

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

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 09, 2025 Apr 09, 2025
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines