Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

160
Visualizações
Photshop: Saving pngs on randomizing function not working

i'm trying to run a script on PS 2021 version to randomize the creation of PNG artworks. I've set up four groups with different layers on it. It randomizes the visibility of layers in a certain way. However, when it comes to saving the image as PNG it prompts the file explorer to save the file in PSD format.

This is the code am using right now:

function Visible() {
    var Grps = app.activeDocument.layerSets;

    //alert("total groups: "+ Grps.length);
    for (var i = 0; i < Grps.length; i++) {
        // Get the amount of layers in a set
        var tmp = app.activeDocument.layerSets[i].layers.length;

        // set the whole group visible
        app.activeDocument.layerSets[i].visible = true;

        var groupChildArr = app.activeDocument.layerSets[i].layers;

        var randLays = Math.floor(Math.random() * tmp);

        groupChildArr[randLays].visible = true;

        Save();

    }
    Revert();
}
function Save() {
    var outFolder = app.activeDocument;

    var outPath = outFolder.path;

    var fName = "PNG";

    var f = new Folder(outPath + "/" + fName);
    if (!f.exists) {
        f.create()
    }
    //alert("before path config");
    var saveFile = new File(outPath + "/" + fName + "/" + "TREE_" + num + ".png");
    pngSaveOptions = new PNGSaveOptions();
    pngSaveOptions.interlaced = false;

    //alert("before save")
    app.activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);
    //alert("after save")
}
function Revert() { 
    var idRvrt = charIDToTypeID("Rvrt"); 
    executeAction(idRvrt, undefined, DialogModes.NO); 
}
var count = prompt("How many versions you want", ""); 
for (var x = 0; x < count; x++) { 
    var num = x + 1; 
    Visible(); 
}

This is how it works, it asks for the number of pieces to generate:

enter image description here

And then it just prompts the explorer on each iteration: enter image description here

Any help would be greatly appreciated!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to suppress any Photoshop dialog boxes that may pop up. At the very start of your script put this:

// Switch off any dialog boxes
displayDialogs = DialogModes.NO; // OFF 

You will also have to flatten the document as well. Add it just before the save:

    activeDocument.flatten();

    Save();
  • Don't worry the revert function puts it back to how it was.
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda