Skip to content

Instantly share code, notes, and snippets.

@sambatlim
Created July 25, 2021 07:30
Show Gist options
  • Save sambatlim/3d145f4dc4b2f5d8ef641b18a39ac93c to your computer and use it in GitHub Desktop.
Save sambatlim/3d145f4dc4b2f5d8ef641b18a39ac93c to your computer and use it in GitHub Desktop.
Script to generate save image from each group in photoshop.
function Main() {
var num = 1;
for (var j = 0; j < app.activeDocument.layerSets[0].layers.length; j++) {
for (var k = 0; k < app.activeDocument.layerSets[1].layers.length; k++) {
for (var l = 0; l < app.activeDocument.layerSets[2].layers.length; l++) {
var groupChildArr1 = app.activeDocument.layerSets[0].layers;
var groupChildArr2 = app.activeDocument.layerSets[1].layers;
var groupChildArr3 = app.activeDocument.layerSets[2].layers;
app.activeDocument.layerSets[0].visible = true;
app.activeDocument.layerSets[1].visible = true;
app.activeDocument.layerSets[2].visible = true;
groupChildArr1[j].visible = true;
groupChildArr2[k].visible = true;
groupChildArr3[l].visible = true;
Save(num);
num++;
Revert();
}
}
}
}
function Save(num) {
var outFolder = app.activeDocument; // psd name
var outPath = outFolder.path;
var fName = "PNG"; // define folder name
var f = new Folder(outPath + "/" + fName);
if (!f.exists) {
f.create()
}
var saveFile = new File(outPath + "/" + fName + "/" + "Pattern_" + num + ".png");
pngSaveOptions = new PNGSaveOptions();
pngSaveOptions.interlaced = false;
app.activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);
}
function Revert() {
var idRvrt = charIDToTypeID("Rvrt");
executeAction(idRvrt, undefined, DialogModes.NO);
}
Main()
@know-sol
Copy link

Im having the same issue. I am also using 2014.

@sambatlim
Copy link
Author

Never try on PS 2014.

@artMayakosha
Copy link

I am using CS6. When I browse for your .JS file I cant see it. Does it not work?
Really great tutorial. Which Photoshop version are you using?

@artMayakosha
Copy link

Works with PS2020. Great job mate!! Long Live King Lim!!

@screwfaceworld
Copy link

bybyspalma : i use ur code above and its working on myside i using PS 2020

@ArtisNegoti
Copy link

Hi
I have used this to create static NFTs. I have a character and then need to change background color and icon. I also have animated the characters. How do I change this code to work on an animated character in photoshop or aftereffects? i.e the character is animated and the background color and icon change

@ArtisNegoti
Copy link

I have managed to get the animation into a video group in Photoshop (as a .mov) and then converted my other groups of layers into groups of video groups. As the file goes through the various layers in the group, it needs to be added to a render queue rather than saved as a png.

@sambatlim
Copy link
Author

It would be great if you share your code here.

@ArtisNegoti
Copy link

ArtisNegoti commented Mar 16, 2022 via email

@ArtisNegoti
Copy link

Hi
Checking to see if you received the email I sent yesterday. Let me know if you are interested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment