@Stephen Marsh - Locked transparency and fill with random color is what I have in mind!
@Stephen Marsh - Locked transparency and fill with random color is what I have in mind!
By @Enixanne
Try this:
/*
Fill Art Layers with Random Colour.jsx
v1.0 - 22nd September 2023, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/a-script-that-autofill-layers-with-a-random-color/m-p/14103781
*/
#target photoshop
function main() {
processAllLayersAndSets(app.activeDocument);
}
activeDocument.suspendHistory('Fill Art Layers with Random Colour.jsx', 'main()');
///// FUNCTIONS /////
function processAllLayersAndSets(obj) {
// Process Layers
for (var i = obj.artLayers.length - 1; 0 <= i; i--) {
activeDocument.activeLayer = obj.artLayers[i];
var randomSolidColor = new SolidColor();
var R = randomSolidColor.rgb.red = Math.round(Math.random() * 255);
var G = randomSolidColor.rgb.green = Math.round(Math.random() * 255);
var B = randomSolidColor.rgb.blue = Math.round(Math.random() * 255);
lockTransparentPixels(true);
randomFGcol(R, G, B);
fill(100, true);
}
// Process Layer Set Layers
for (var i = obj.layerSets.length - 1; 0 <= i; i--) {
processAllLayersAndSets(obj.layerSets[i]);
}
}
function randomFGcol(red, grain, blue) {
function s2t(s) {
return app.stringIDToTypeID(s);
}
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
var reference = new ActionReference();
reference.putProperty(s2t("color"), s2t("foregroundColor"));
descriptor.putReference(s2t("null"), reference);
descriptor2.putDouble(s2t("red"), red);
descriptor2.putDouble(s2t("grain"), grain);
descriptor2.putDouble(s2t("blue"), blue);
descriptor.putObject(s2t("to"), s2t("RGBColor"), descriptor2);
descriptor.putString(s2t("source"), "photoshopPicker");
executeAction(s2t("set"), descriptor, DialogModes.NO);
}
function lockTransparentPixels(protectTransparency) {
function s2t(s) {
return app.stringIDToTypeID(s);
}
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
var reference = new ActionReference();
reference.putEnumerated( s2t( "layer" ), s2t( "ordinal" ), s2t( "targetEnum" ));
descriptor.putReference( s2t( "null" ), reference );
descriptor2.putBoolean( s2t( "protectTransparency" ), protectTransparency );
descriptor.putObject( s2t( "layerLocking" ), s2t( "layerLocking" ), descriptor2 );
executeAction( s2t( "applyLocking" ), descriptor, DialogModes.NO );
}
function fill(opacity, preserveTransparency) {
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
descriptor.putEnumerated(s2t("using"), s2t("fillContents"), s2t("foregroundColor"));
descriptor.putUnitDouble(s2t("opacity"), s2t("percentUnit"), opacity);
descriptor.putEnumerated(s2t("mode"), s2t("blendMode"), s2t("normal"));
descriptor.putBoolean(s2t("preserveTransparency"), preserveTransparency);
executeAction(s2t("fill"), descriptor, DialogModes.NO);
}
https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html