Randomize Layer Styles

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

XilE

Randomize Layer Styles

Post by XilE »

If I log the layer styles minimum and maximum output settings plus on and off how hard would it be to make a script randomize the settings? I'm not sure if something like this already exist but it's just something that has me curious. A pointer in the right direction would be greatly appreciated.

Thanks!
-Drew

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

pfaffenbichler

Randomize Layer Styles

Post by pfaffenbichler »

Is this about one Layer Style or all Layer Styles?

For one Style I think it is not very complicated.
Record the Action Manager code for the creation of the Style with ScriptingListener.plugin and wrap it into a function that takes the elements you want to randomize as arguments.
Feeding the function with random values based on Math.random() will take some finagling for non-numeric values and for numeric values you probably just need to figure out the minimum and maximum possible values and round to integers between those.

Edit: This would create a partly random Stroke, I haven’t bothered to find out the values for »Inside« etc., but just randomized the width and the RGB-colors.
Code: Select all// 2012, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
   var myDocument = app.activeDocument;
   try {addStroke (randomNumberBetween(0, 250), randomNumberBetween(0, 255), randomNumberBetween(0, 255), randomNumberBetween(0, 255))}
   catch (e) {}
   };
////// random integer between two values //////
function randomNumberBetween (theLowest, theHighest) {
   var theResult = theLowest + Math.floor(Math.random() * (theHighest - theLowest + 1));
   return theResult
   };
////// add stroke //////
function addStroke (theWidth, theR, theG, theB) {
// =======================================================
var idsetd = charIDToTypeID( "setd" );
    var desc8 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref4 = new ActionReference();
        var idPrpr = charIDToTypeID( "Prpr" );
        var idLefx = charIDToTypeID( "Lefx" );
        ref4.putProperty( idPrpr, idLefx );
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref4.putEnumerated( idLyr, idOrdn, idTrgt );
    desc8.putReference( idnull, ref4 );
    var idT = charIDToTypeID( "T   " );
        var desc9 = new ActionDescriptor();
        var idScl = charIDToTypeID( "Scl " );
        var idPrc = charIDToTypeID( "#Prc" );
        desc9.putUnitDouble( idScl, idPrc, 416.666667 );
        var idFrFX = charIDToTypeID( "FrFX" );
            var desc10 = new ActionDescriptor();
            var idenab = charIDToTypeID( "enab" );
            desc10.putBoolean( idenab, true );
            var idStyl = charIDToTypeID( "Styl" );
            var idFStl = charIDToTypeID( "FStl" );
            var idOutF = charIDToTypeID( "OutF" );
            desc10.putEnumerated( idStyl, idFStl, idOutF );
            var idPntT = charIDToTypeID( "PntT" );
            var idFrFl = charIDToTypeID( "FrFl" );
            var idSClr = charIDToTypeID( "SClr" );
            desc10.putEnumerated( idPntT, idFrFl, idSClr );
            var idMd = charIDToTypeID( "Md  " );
            var idBlnM = charIDToTypeID( "BlnM" );
            var idNrml = charIDToTypeID( "Nrml" );
            desc10.putEnumerated( idMd, idBlnM, idNrml );
            var idOpct = charIDToTypeID( "Opct" );
            var idPrc = charIDToTypeID( "#Prc" );
            desc10.putUnitDouble( idOpct, idPrc, 100.000000 );
            var idSz = charIDToTypeID( "Sz  " );
            var idPxl = charIDToTypeID( "#Pxl" );
            desc10.putUnitDouble( idSz, idPxl, theWidth );
            var idClr = charIDToTypeID( "Clr " );
                var desc11 = new ActionDescriptor();
                var idRd = charIDToTypeID( "Rd  " );
                desc11.putDouble( idRd, theR );
                var idGrn = charIDToTypeID( "Grn " );
                desc11.putDouble( idGrn, theG );
                var idBl = charIDToTypeID( "Bl  " );
                desc11.putDouble( idBl, theB );
            var idRGBC = charIDToTypeID( "RGBC" );
            desc10.putObject( idClr, idRGBC, desc11 );
        var idFrFX = charIDToTypeID( "FrFX" );
        desc9.putObject( idFrFX, idFrFX, desc10 );
    var idLefx = charIDToTypeID( "Lefx" );
    desc8.putObject( idT, idLefx, desc9 );
executeAction( idsetd, desc8, DialogModes.NO );
};
Mike Hale

Randomize Layer Styles

Post by Mike Hale »

Just to add to what pfaffenbichler posted - I think that if you are talking about creating new layer effects with random settings how easy it would be would depend on which effect and what settings you want randomized. For example with the stroke example posted is would be easy to randomize the stroke position because there are only 3 possible choices. It would be much harder to randomize between color, gradient, and pattern for the fill type.

And changing an existing effect with random setting would be much harder.
XilE

Randomize Layer Styles

Post by XilE »

I see thank you very much guys.
pfaffenbichler

Randomize Layer Styles

Post by pfaffenbichler »

May I ask if you had anything particular in mind with regard to randomized Layer Styles?