Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Auto layer dupping

New Here ,
Feb 06, 2018 Feb 06, 2018

I'm trying to find a way to duplicate an image in one layer and duplicate it multiple times randomly rotating, sizing and repositioning each one.

Does anyone know of anything like this or even close?

TOPICS
Actions and scripting
691
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Feb 06, 2018 Feb 06, 2018

Its just a matter of writing some functions on how you want to manipulate the layer - normally by using scriptListener, then creating a loop to loop though how many times you want to repeat something and adding a random calculation into the rotation, size, etc. For example in this image, I wanted to create tiles in a somewhat close order to the original image, but I wanted each tile offset a bit. So I create some code that made a selection, but I added a random element to it to move it around, then I moved it back into order, so the tiles were lined up.

Basically to add some randomness to a number you use something like this:

var myRandomNum = Math.random()*theRange + theOffset

You times the Math.random by how much of a spread you want, the you either add or subtract the offset.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 16, 2018 Mar 16, 2018

Chuck what did he do to you to make you treat him the way you did? Man dices to pieces

JJMack
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 16, 2018 Mar 16, 2018
LATEST

My father. Sometime I really felt like I really didn't know him.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 07, 2018 Feb 07, 2018

Another point: When people speak of »random« they often seem to mean a limited randomness, so one should give some thought to how one intends to limit the randomness within any variant beforehand.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Feb 07, 2018 Feb 07, 2018

What about the "random fill"-script as starting point?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 07, 2018 Feb 07, 2018

Good idea.

But depending on what the OP is after exactly (should individual Layers be kept editable, should Smart Objects be used, …) it may not suffice.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 07, 2018 Feb 07, 2018

(edited)

// duplicate and transform layer;

// 2018, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

var docHeight = myDocument.height.as('px');

var docWidth = myDocument.width.as('px');

var theID = getLayerId();

var ref = new ActionReference();

ref.putProperty(charIDToTypeID( "Prpr" ), stringIDToTypeID("bounds"));

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

var layerDesc = executeActionGet(ref);

var bounds = layerDesc.getObjectValue(stringIDToTypeID("bounds"));

var left = bounds.getUnitDoubleValue(stringIDToTypeID("left"));

var top = bounds.getUnitDoubleValue(stringIDToTypeID("top"));

var right = bounds.getUnitDoubleValue(stringIDToTypeID("right"));

var bottom = bounds.getUnitDoubleValue(stringIDToTypeID("bottom"));

var layerX = left + (right - left) / 2;

var layerY = top + (bottom - top) / 2;

// duplicate;

for (var m = 0; m < 50; m++) {

var centerX = Math.random()*docWidth;

var centerY = Math.random()*docHeight;

var theScale = Math.random()*60+40;

layerDuplicateScaleRotate(theID, centerX - layerX, centerY - layerY, theScale, theScale, Math.random()*360);

}

};

////// duplicate layer (id, xOffset, yOffset, theXScale, theYScale, theAngle) //////

function layerDuplicateScaleRotate (theID, xOffset, yOffset, theXScale, theYScale, theAngle) {

// based on code by mike hale, via paul riggott;

var ref = new ActionReference();

    ref.putIdentifier(charIDToTypeID("Lyr "), theID);

    var desc = new ActionDescriptor();

    desc.putReference(charIDToTypeID("null"), ref );

    desc.putBoolean( charIDToTypeID( "MkVs" ), false );

   try{

    executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );

}catch(e){

alert(e.message);

};

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

    var desc23 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref2 = new ActionReference();

        ref2.putIdentifier ( charIDToTypeID( "Lyr " ), theID );

//        ref2.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );

    desc23.putReference( idnull, ref2 );

    desc23.putEnumerated( charIDToTypeID( "FTcs" ), charIDToTypeID( "QCSt" ), charIDToTypeID( "Qcsa" ) );

    var idOfst = charIDToTypeID( "Ofst" );

        var desc24 = new ActionDescriptor();

        var idPxl = charIDToTypeID( "#Pxl" );

        desc24.putUnitDouble( charIDToTypeID( "Hrzn" ), idPxl, xOffset );

        desc24.putUnitDouble( charIDToTypeID( "Vrtc" ), idPxl, yOffset );

    var idOfst = charIDToTypeID( "Ofst" );

    desc23.putObject( idOfst, idOfst, desc24 );

    var idPrc = charIDToTypeID( "#Prc" );

    desc23.putUnitDouble( charIDToTypeID( "Wdth" ), idPrc, theXScale );

    desc23.putUnitDouble( charIDToTypeID( "Hght" ), idPrc, theXScale );

    desc23.putUnitDouble( charIDToTypeID( "Angl" ), charIDToTypeID( "#Ang" ), theAngle );

    desc23.putEnumerated( charIDToTypeID( "Intr" ), charIDToTypeID( "Intp" ), stringIDToTypeID( "bicubicAutomatic" ) );

    desc23.putBoolean( charIDToTypeID( "Cpy " ), true );

executeAction( charIDToTypeID( "Trnf" ), desc23, DialogModes.NO );

};

// by mike hale, via paul riggott;

// http://forums.adobe.com/message/1944754#1944754

function getLayerId(){

//Assumes activeDocument and activeLayer

var ref = new ActionReference();

ref.putProperty(charIDToTypeID( "Prpr" ), charIDToTypeID('LyrI'));

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

d = executeActionGet(ref);

return d.getInteger(charIDToTypeID('LyrI'));

};

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 21, 2018 Feb 21, 2018

Have you tested the edited Script?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 16, 2018 Mar 16, 2018

I wonder why some people ask for something they might get answer for, but are not anymore interested if that happened!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines