First post.
I found the below code from this post
viewtopic.php?f=66&t=40450&p=169300&hil ... or#p169300
That almost does what I am looking for.
I need to auto-create +300 solid color images from a series of pre-selected hex codes.
But I need to name each file created with its corresponding color hex value.
So, instead of these images created:
Solid Color 0 5x5.tif
Solid Color 1 5x5.tif
Solid Color 2 5x5.tif
Solid Color 3 5x5.tif
I need these images created with their corresponding color hex value:
dcb149.tif
e8d279.tif
bd6124.tif
c53c12.tif
I tried to modify the code but cannot find where to do it.
My knowledge of scripting is none.
Second minor request: Instead of .tif files I would need .png files.
Thank you in advance for your kind help.
ddcg wrote: ↑Tue Dec 18, 2018 9:09 pm A little late to the party here...stumbled across your question and thought I'd share something I created recently that will do a similar thing.
This script will create a solid color layer with a random color from a series of pre-selected hex codes...so the idea is you populate the array with hex vals for colors you want it to choose from and then it'll randomly pick one of those colors for each iteration of the loop.
The loop is determined by 'n'. Change the value of n to however many files you want it to create and that's it; hit play and walk away
Code: Select all
var currentRulers = app.preferences.rulerUnits; app.preferences.rulerUnits = Units.INCHES; // SAVE PATH var rootFolder = new Folder(Folder.desktop + "/Solid Colors"); // CREATE SAVE PATH IF IT DOESN'T EXIST if (!rootFolder.exists) { rootFolder.create() } // RANDOM NUMBER GENERATOR function rando(min, max) { return Math.floor(Math.random() * (max - min + 1) ) + min; } // SAVE AS A TIFF function saveTiff(savePath, newName) { var activeDoc = app.activeDocument; var w = activeDoc.width.value var h = activeDoc.height.value var revWidth = (Math.floor(w)).toString(); var revHeight = (Math.floor(h)).toString(); var saveOpts = new TiffSaveOptions(); saveOpts.alphaChannels = false; saveOpts.interleaveChannels = true; saveOpts.imageCompression = TIFFEncoding.TIFFLZW; activeDoc.saveAs(new File(savePath + "/" + newName + " " + revWidth + "x" + revHeight + ".tif"), saveOpts); activeDoc.close(); } var n = 10; // CHANGE N TO THE NUMBER OF FILES YOU WANT THE SCRIPT TO CREATE var masterWidth = 5; // SET YOUR DOCUMENT WIDTH var masterHeight = 5; // SET YOUR DOCUMENT HEIGHT var masterRes = 300; // SET YOUR DOCUMENT RESOLUTION // ADD MORE HEX CODES TO INCLUDE DIFFERENT COLORS var hexVals = [ "dcb149", //mustard yellow "e8d279", //canary yellow "bd6124", //light orange "c53c12", //orange red "991a1a", //dk red "991a38", //fuscia "f1725e", //salmon "441848", //plum "3c1f35", //blackberry "2d1c43", //grape "5088ac", //sky blue "20beda", //baby blue "426277", //ocean blue "1b2a4a", //navy blue "274685", //royal blue "468684", //sea foam blue / green "3a6c4a", //kelly green "304d2d", //forest green "2e3a1c", //army green "4d541d", //moss green "6f6a6c", //warm med gray "252424", //warm dk gray "b9b6b7" //light gray ] for (i = 0; i < n; i++) { var h = rando(0, (hexVals.length - 1)); app.foregroundColor.rgb.hexValue = hexVals[h]; //alert(app.foregroundColor.rgb.hexValue) app.documents.add(masterWidth, masterHeight, masterRes, "Untitled " + i, NewDocumentMode.RGB, DocumentFill.WHITE); var doc = app.activeDocument; var colorLayer = doc.artLayers.add(); app.activeLayer = colorLayer; doc.selection.selectAll(); doc.selection.fill(app.foregroundColor); colorLayer.move(doc.backgroundLayer, ElementPlacement.PLACEBEFORE); saveTiff(rootFolder, "Solid Color " + i) } app.preferences.rulerUnits = currentRulers;