Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
JS / JSX Script para generar PNG únicos a partir de todas las permutaciones en todos los grupos de capas de Photoshop y sus capas de Photoshop

Estoy buscando entrar en el arte generativo. Mi idea es hacer que Photoshop (CS5) genere un PNG único para todas las permutaciones que existen mientras el script itera a través de cada CAPA en cada GRUPO DE CAPAS (conjuntos de capas).

Como ejemplo, sería similar a un generador de caracteres donde: Los conjuntos de capas PADRES consisten en partes o ubicaciones en la cara/cuerpo (A,B) Las capas HIJOS consisten en accesorios/estilos (1,2,3) De modo que todos los PNG generados las permutaciones serían: A1B1,A2B1,A3B1;A2B1,A2B2,A2B3;A3B1,A3B2,A3B3 únicamente. (A1A2, A2A3, A1A3; B1B2, B2B3, B1B3 no son necesarios; A1, A2, A3, B1, B2, B3 independientes no son necesarios).

Encontré un código de @Mr.Online que genera combinaciones aleatorias y potencialmente redundantes a partir de la cantidad ingresada por el usuario. Su secuencia de comandos requiere que el usuario oculte todas las capas antes de ejecutarlas.

Muchas gracias. Espero que esto ayude:

 function Visible() { var Grps = app.activeDocument.layerSets; // loops through all groups for(var i = 0; i < Grps.length; i++){ var tmp = app.activeDocument.layerSets[i].layers.length; 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; // 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); } // Original code - revert function does not work // for some users //function Revert(){ // var idslct = charIDToTypeID( "slct" ); // var desc300 = new ActionDescriptor(); // var idnull = charIDToTypeID( "null" ); // var ref163 = new ActionReference(); // var idSnpS = charIDToTypeID( "SnpS" ); // ref163.putName( idSnpS, "test.psd" ); // desc300.putReference( idnull, ref163 ); // executeAction( idslct, desc300, DialogModes.NO ); //} function Revert(){ var idRvrt = charIDToTypeID( "Rvrt" ); executeAction( idRvrt, undefined, DialogModes.NO ); } var count = prompt("How many patterns you want",""); for (var x=0 ; x<count;x++){ var num = x+1; Visible(); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Como dices, debes ignorar las capas aleatorias. Sin embargo, si conoce la cantidad de capas y grupos, es bastante sencillo:

 show_layers("A", "1"); show_layers("B", "1"); function show_layers(g, n) { // g is the name of the group (layerset) // n is the name of the layer (artlayer) srcDoc.activeLayer = srcDoc.layerSets.getByName(g).artLayers.getByName(n); srcDoc.activeLayer.visible = true; }

Entonces, suponiendo que todas las capas estén desactivadas, puede obtener las capas por nombre y luego hacerlas visibles.

Desactivar todas las capas es un poco más complicado. Debe recorrer todos los grupos y luego recorrer sus subcapas. Trabajar con grupos es un poco una curva de aprendizaje.

 function switch_off_all_layers(bool) { var numLayers = app.activeDocument.layers.length; // want to hide the background as well? // default: background = visible if (bool == undefined) bool = false; if (bool == false) { numLayers -=1; // -1 for background } for(var i = 0 ; i < numLayers; i++) { if (app.activeDocument.layers[i].typename == "LayerSet") { app.activeDocument.layers[i].visible = true; var subDoc = app.activeDocument.layers[i]; var numOfSubLayers = subDoc.layers.length; for (var j = numOfSubLayers -1; j >= 0; j--) { var tempSubLayer = subDoc.layers[j]; tempSubLayer.visible = false; } } } }

Además de mi explicación, si no puede proporcionar las capas y los nombres del grupo, entonces desea recorrer todos los grupos y todas las capas.

 var groupLayers = []; var artLayers = []; var theLayers = collectAllLayers(app.activeDocument, 0); alert("Group layers\n" + groupLayers); alert("Art layers\n" + artLayers); // function collect all layers function collectAllLayers (theParent, level) { for (var m = theParent.layers.length - 1; m >= 0; m--) { var theLayer = theParent.layers[m]; // apply the function to layersets; if (theLayer.typename == "ArtLayer") { if (theLayer.isBackgroundLayer == true) { // add background layer (if needed) // artLayers.push(theLayer.name); } else { // find the art layers artLayers.push(theLayer.name); } } else { // find the group layers groupLayers.push(theLayer.name); collectAllLayers(theLayer, level + 1) } } }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!