Skip to main content
Participating Frequently
April 26, 2015
Answered

need help with randomize script, willing to pay

  • April 26, 2015
  • 2 replies
  • 7152 views

I'm trying to find someone who can help me script this. I would be willing to pay for this so please email me if interested. So what is need is a script that allows me to import all the images from a folder, put it in one document and randomize rotations transforms and layer modes.I'm looking for a way to generate more abstract art from photographs and things I've shot. Preferably it would be great if there was a floating panel that would let me randomioze more if I didn't like the result. Any one heard of anything like this?

This topic has been closed for replies.
Correct answer c.pfaffenbichler

// randomly place smart objects;

// 2015, use it at your own risk;

#target "photoshop-70.032"

if (app.documents.length > 0) {

app.activeDocument.suspendHistory("place", "main ()");

};

////////////////////////////////////

function main () {

// the file;

var myDocument = app.activeDocument;

var theFiles = selectFile(true);

if (theFiles) {

// the blend modes;

var blendModes = [BlendMode.NORMAL, BlendMode.SCREEN, BlendMode.MULTIPLY, BlendMode.OVERLAY];

// set to pixels;

var startRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

// get half width and height;

var hori = myDocument.width/2;

var vert = myDocument.height/2;

var theLayers = new Array;

// rotation between -60˚ and 60˚;

var rot = new Array;

for (var n = 0; n < theFiles.length; n++) {

  rot.push((0.5-Math.random())*120)

  };

// blend modes;

var mod = new Array;

for (var o = 0; o < theFiles.length; o++) {

  mod.push(blendModes[Math.floor(Math.random()*blendModes.length)])

  };

// place;

for (var m = 0; m < theFiles.length; m++) {

// set scale between 50 and 100%;

  var theScale = 50+(Math.random()*50);

  var thisLayer = placeScaleRotateFile (theFiles, (0.5-Math.random())*hori, (0.5-Math.random())*vert, theScale, theScale, rot, false);

  myDocument.activeLayer.blendMode = mod;

  theLayers.push(thisLayer);

  };

// reset;

app.preferences.rulerUnits = startRulerUnits;

}

};

////// place //////

function placeScaleRotateFile (file, xOffset, yOffset, theXScale, theYScale, theAngle, linked) {

// =======================================================

var idPlc = charIDToTypeID( "Plc " );

    var desc5 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

    desc5.putPath( idnull, new File( file ) );

    var idFTcs = charIDToTypeID( "FTcs" );

    var idQCSt = charIDToTypeID( "QCSt" );

    var idQcsa = charIDToTypeID( "Qcsa" );

    desc5.putEnumerated( idFTcs, idQCSt, idQcsa );

    var idOfst = charIDToTypeID( "Ofst" );

        var desc6 = new ActionDescriptor();

        var idHrzn = charIDToTypeID( "Hrzn" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc6.putUnitDouble( idHrzn, idPxl, xOffset );

        var idVrtc = charIDToTypeID( "Vrtc" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc6.putUnitDouble( idVrtc, idPxl, yOffset );

    var idOfst = charIDToTypeID( "Ofst" );

    desc5.putObject( idOfst, idOfst, desc6 );

    var idWdth = charIDToTypeID( "Wdth" );

    var idPrc = charIDToTypeID( "#Prc" );

    desc5.putUnitDouble( idWdth, idPrc, theYScale );

    var idHght = charIDToTypeID( "Hght" );

    var idPrc = charIDToTypeID( "#Prc" );

    desc5.putUnitDouble( idHght, idPrc, theXScale );

    var idAngl = charIDToTypeID( "Angl" );

    var idAng = charIDToTypeID( "#Ang" );

    desc5.putUnitDouble( idAngl, idAng,theAngle );

if (linked == true) {

    var idLnkd = charIDToTypeID( "Lnkd" );

    desc5.putBoolean( idLnkd, true );

  };

executeAction( idPlc, desc5, DialogModes.NO );

// get layerid;

var ref = new ActionReference();

ref.putProperty (stringIDToTypeID ("property"), stringIDToTypeID ("layerID"));

ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

var layerDesc = executeActionGet(ref);

var layerID = layerDesc.getInteger (stringIDToTypeID ("layerID"));

// =======================================================

return [app.activeDocument.activeLayer, layerID];

};

////// select file //////

function selectFile (multi) {

if (multi == true) {var theString = "please select files"}

else {var theString = "please select one file"};

if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog (theString, '*.jpg;*.tif;*.psd;*.png', multi)}

else {var theFiles = File.openDialog (theString, getFiles, multi)};

////// filter files  for mac //////

function getFiles (theFile) {

    if (theFile.name.match(/\.(jpg|tif|psd|png)$/i) || theFile.constructor.name == "Folder") {

        return true

        };

  };

return theFiles

};

2 replies

c.pfaffenbichler
Community Expert
c.pfaffenbichlerCommunity ExpertCorrect answer
Community Expert
April 27, 2015

// randomly place smart objects;

// 2015, use it at your own risk;

#target "photoshop-70.032"

if (app.documents.length > 0) {

app.activeDocument.suspendHistory("place", "main ()");

};

////////////////////////////////////

function main () {

// the file;

var myDocument = app.activeDocument;

var theFiles = selectFile(true);

if (theFiles) {

// the blend modes;

var blendModes = [BlendMode.NORMAL, BlendMode.SCREEN, BlendMode.MULTIPLY, BlendMode.OVERLAY];

// set to pixels;

var startRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

// get half width and height;

var hori = myDocument.width/2;

var vert = myDocument.height/2;

var theLayers = new Array;

// rotation between -60˚ and 60˚;

var rot = new Array;

for (var n = 0; n < theFiles.length; n++) {

  rot.push((0.5-Math.random())*120)

  };

// blend modes;

var mod = new Array;

for (var o = 0; o < theFiles.length; o++) {

  mod.push(blendModes[Math.floor(Math.random()*blendModes.length)])

  };

// place;

for (var m = 0; m < theFiles.length; m++) {

// set scale between 50 and 100%;

  var theScale = 50+(Math.random()*50);

  var thisLayer = placeScaleRotateFile (theFiles, (0.5-Math.random())*hori, (0.5-Math.random())*vert, theScale, theScale, rot, false);

  myDocument.activeLayer.blendMode = mod;

  theLayers.push(thisLayer);

  };

// reset;

app.preferences.rulerUnits = startRulerUnits;

}

};

////// place //////

function placeScaleRotateFile (file, xOffset, yOffset, theXScale, theYScale, theAngle, linked) {

// =======================================================

var idPlc = charIDToTypeID( "Plc " );

    var desc5 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

    desc5.putPath( idnull, new File( file ) );

    var idFTcs = charIDToTypeID( "FTcs" );

    var idQCSt = charIDToTypeID( "QCSt" );

    var idQcsa = charIDToTypeID( "Qcsa" );

    desc5.putEnumerated( idFTcs, idQCSt, idQcsa );

    var idOfst = charIDToTypeID( "Ofst" );

        var desc6 = new ActionDescriptor();

        var idHrzn = charIDToTypeID( "Hrzn" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc6.putUnitDouble( idHrzn, idPxl, xOffset );

        var idVrtc = charIDToTypeID( "Vrtc" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc6.putUnitDouble( idVrtc, idPxl, yOffset );

    var idOfst = charIDToTypeID( "Ofst" );

    desc5.putObject( idOfst, idOfst, desc6 );

    var idWdth = charIDToTypeID( "Wdth" );

    var idPrc = charIDToTypeID( "#Prc" );

    desc5.putUnitDouble( idWdth, idPrc, theYScale );

    var idHght = charIDToTypeID( "Hght" );

    var idPrc = charIDToTypeID( "#Prc" );

    desc5.putUnitDouble( idHght, idPrc, theXScale );

    var idAngl = charIDToTypeID( "Angl" );

    var idAng = charIDToTypeID( "#Ang" );

    desc5.putUnitDouble( idAngl, idAng,theAngle );

if (linked == true) {

    var idLnkd = charIDToTypeID( "Lnkd" );

    desc5.putBoolean( idLnkd, true );

  };

executeAction( idPlc, desc5, DialogModes.NO );

// get layerid;

var ref = new ActionReference();

ref.putProperty (stringIDToTypeID ("property"), stringIDToTypeID ("layerID"));

ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

var layerDesc = executeActionGet(ref);

var layerID = layerDesc.getInteger (stringIDToTypeID ("layerID"));

// =======================================================

return [app.activeDocument.activeLayer, layerID];

};

////// select file //////

function selectFile (multi) {

if (multi == true) {var theString = "please select files"}

else {var theString = "please select one file"};

if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog (theString, '*.jpg;*.tif;*.psd;*.png', multi)}

else {var theFiles = File.openDialog (theString, getFiles, multi)};

////// filter files  for mac //////

function getFiles (theFile) {

    if (theFile.name.match(/\.(jpg|tif|psd|png)$/i) || theFile.constructor.name == "Folder") {

        return true

        };

  };

return theFiles

};

emanshiuAuthor
Participating Frequently
April 27, 2015

it works! thanks so much! thats what I was looking for! Sorry if I was being lame!

c.pfaffenbichler
Community Expert
Community Expert
April 27, 2015

If you want more/other Blend Modes to be chosen you need to amend the line

  1. var blendModes = [BlendMode.NORMAL, BlendMode.SCREEN, BlendMode.MULTIPLY, BlendMode.OVERLAY];

accordingly, that defines the Array from which the applied ones are (pseudo-)randomly chosen.

c.pfaffenbichler
Community Expert
Community Expert
April 26, 2015

I have at times tinkered with randomisations in Photoshop, maybe this code can provide a starting point for you.

Though you might find that (pseudo-)random is not what you want but rather a limited randomness which would necessitate levelling out the distribution.

// randomly place smart objects;

// 2015, use it at your own risk;

#target "photoshop-70.032"

if (app.documents.length > 0) {

app.activeDocument.suspendHistory("place", "main ()");

};

////////////////////////////////////

function main () {

// the file;

var myDocument = app.activeDocument;

var theFiles = selectFile(true);

if (theFiles) {

// set to pixels;

var startRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

// get half width and height;

var hori = myDocument.width/2;

var vert = myDocument.height/2;

// place;

var theLayers = new Array;

var rot = new Array;

// rotation between -60˚ and 60˚;

for (var n = 0; n < theFiles.length; n++) {

  rot.push((0.5-Math.random())*120)

  };

for (var m = 0; m < theFiles.length; m++) {

// set scale between 50 and 100%;

  var theScale = 50+(Math.random()*50);

  var thisLayer = placeScaleRotateFile (theFiles, (0.5-Math.random())*hori, (0.5-Math.random())*vert, theScale, theScale, rot, false);

  theLayers.push(thisLayer);

  };

// reset;

app.preferences.rulerUnits = startRulerUnits;

}

};

////// place //////

function placeScaleRotateFile (file, xOffset, yOffset, theXScale, theYScale, theAngle, linked) {

// =======================================================

var idPlc = charIDToTypeID( "Plc " );

    var desc5 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

    desc5.putPath( idnull, new File( file ) );

    var idFTcs = charIDToTypeID( "FTcs" );

    var idQCSt = charIDToTypeID( "QCSt" );

    var idQcsa = charIDToTypeID( "Qcsa" );

    desc5.putEnumerated( idFTcs, idQCSt, idQcsa );

    var idOfst = charIDToTypeID( "Ofst" );

        var desc6 = new ActionDescriptor();

        var idHrzn = charIDToTypeID( "Hrzn" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc6.putUnitDouble( idHrzn, idPxl, xOffset );

        var idVrtc = charIDToTypeID( "Vrtc" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc6.putUnitDouble( idVrtc, idPxl, yOffset );

    var idOfst = charIDToTypeID( "Ofst" );

    desc5.putObject( idOfst, idOfst, desc6 );

    var idWdth = charIDToTypeID( "Wdth" );

    var idPrc = charIDToTypeID( "#Prc" );

    desc5.putUnitDouble( idWdth, idPrc, theYScale );

    var idHght = charIDToTypeID( "Hght" );

    var idPrc = charIDToTypeID( "#Prc" );

    desc5.putUnitDouble( idHght, idPrc, theXScale );

    var idAngl = charIDToTypeID( "Angl" );

    var idAng = charIDToTypeID( "#Ang" );

    desc5.putUnitDouble( idAngl, idAng,theAngle );

if (linked == true) {

    var idLnkd = charIDToTypeID( "Lnkd" );

    desc5.putBoolean( idLnkd, true );

  };

executeAction( idPlc, desc5, DialogModes.NO );

// get layerid;

var ref = new ActionReference();

ref.putProperty (stringIDToTypeID ("property"), stringIDToTypeID ("layerID"));

ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

var layerDesc = executeActionGet(ref);

var layerID = layerDesc.getInteger (stringIDToTypeID ("layerID"));

// =======================================================

return [app.activeDocument.activeLayer, layerID];

};

////// select file //////

function selectFile (multi) {

if (multi == true) {var theString = "please select files"}

else {var theString = "please select one file"};

if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog (theString, '*.jpg;*.tif;*.psd;*.png', multi)}

else {var theFiles = File.openDialog (theString, getFiles, multi)};

////// filter files  for mac //////

function getFiles (theFile) {

    if (theFile.name.match(/\.(jpg|tif|psd|png)$/i) || theFile.constructor.name == "Folder") {

        return true

        };

  };

return theFiles

};

Chuck Uebele
Community Expert
Community Expert
April 26, 2015

Nice Christoph. Good to see others are doing randomizes scripts.

Script to randomize layer order:

#target photoshop

var docRef = activeDocument

var totalLayerNum = docRef.layers.length

var moveLayer

var relLayer

for (var i=0;i<docRef.layers.length;i++){

    relLayer = docRef.layers[0]

    moveLayer = docRef.layers[Math.floor (Math.random()*totalLayerNum)]

    moveLayer.move(relLayer,ElementPlacement.PLACEBEFORE)

    $.writeln(moveLayer.name)

}

c.pfaffenbichler
Community Expert
Community Expert
April 27, 2015

csuebele, nice effect on the ellipsoidized dog-image.

How long does your Script run on an image like that usually?

I assume you worked with Shape Layers here?

Do you offer your services professionally and if so are you willing to pursue this issue for the original poster (as they stated they were willing to pay)?

Because so far the Scripts I posted have not touched on the repeated randomisation via a panel mentioned in

Preferably it would be great if there was a floating panel that would let me randomioze more if I didn't like the result.

and while I might be willing to post an example for a dialog affecting one of the features (position, scale, rotation, Blend Mode) I do not intend to write that all up …