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

Random Layers scale and opacity

New Here ,
Jun 11, 2018 Jun 11, 2018

Hi All, i found this script which is great in illustrator, however i want to do the same but in Photoshop. Would it be possible? Thank you.

aDoc = app.activeDocument;

aSel = aDoc.selection;



opMin = Number(prompt("min (0-1000%)", 0));

opMax = Number(prompt("max (0-1000%)", 200));


if(opMin > opMax)

{

    temp = opMin;

    opMin = opMax;

    opMax = temp;

}

if(opMin<0)

    opMIn = 0;

if(opMax>1000)

    opMax = 1000;


for(i=0; i<nSel; i++)

{

    resScale = Math.floor(Math.random() * (opMax - opMin + 1)) + opMin;

    aSel[i].resize(resScale, resScale);

}

TOPICS
Actions and scripting
3.3K
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
Explorer ,
Jun 11, 2018 Jun 11, 2018

Is the goal to apply a (different) random opacity and rescale to each layer?

I cleaned up the formatting of the code you pasted to make it easier to see what was going on:

#target photoshop

var aDoc = app.activeDocument;

var aSel = aDoc.selection;

var opMin = Number(prompt("min (0-1000%)", 0));

var opMax = Number(prompt("max (0-1000%)", 200));

if(opMin > opMax){

    temp = opMin;

    opMin = opMax;

    opMax = temp;

    }

if(opMin<0){

    opMIn = 0;

    }

if(opMax>1000){

    opMax = 1000;

    }

for(i=0; i<nSel; i++){

    var resScale = Math.floor(Math.random() * (opMax - opMin + 1)) + opMin;

    aSel.resize(resScale, resScale);

}

If my interpretation about what you are trying to do is correct, in line 4 you will want to use the aDoc.artLayers or aDoc.layerSets collections to grab the layers to loop through.

Another issue is in line 23 in which nSel is used (without having been declared). Presumably you would want to set this to the total number of layers you want to loop through.

The other confusing portion is line 24 in which opMin and opMax (the min and max for the desired opacity ranges?) are used to calculate the rescale factor. Should the rescaling depend on the opacity?

Hopefully this can get you started down the path to what you want to accomplish.

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
New Here ,
Jun 11, 2018 Jun 11, 2018

Hi Sidpalas thank you for quick response, i tried your code but it didn't work. I don't have any background in scripting but i tried to play with the code and i still cant get it to work.

Ps. i dont know why i dont have much options in pasting the code its always colored.

  • #target photoshop
  • var aDoc = app.activeDocument
  • var aSel = aDoc.layerSets
  • var opMin = Number(prompt("min (0-100%)", 50)); 
  • var opMax = Number(prompt("max (0-100%)", 100)); 
  • if(opMin > opMax){ 
  • temp = opMin
  • opMin = opMax
  • opMax = temp
  •   } 
  • if(opMin<0){ 
  • opMIn = 0
  •   } 
  • if(opMax>1000){ 
  • opMax = 1000
  •   } 
  • for(i=0; i<aSel; i++){ 
  • var resScale = Math.floor(Math.random() * (opMax - opMin + 1)) + opMin
  • aSel[i].resize(resScale, resScale); 

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
Explorer ,
Jun 12, 2018 Jun 12, 2018

I didn't change the content of the code you pasted (only changed the formatting to make it easier to read ) so it makes sense that it still wouldn't work.

If you were to more clearly state what it is you are trying to accomplish, someone here might be able to help, I just wasn't sure what exactly the goal was.

When it comes to pasting code into the forum, if you paste it in as plain text and then click the "Use advanced editor" link, followed by ">>", and choose Syntax Highlighting for Javascript, it will look as mine does.

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
New Here ,
Jun 12, 2018 Jun 12, 2018

hi yeah the goal is if i have already created layers is to ramndomize each layer opacity and scale

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
New Here ,
Jun 12, 2018 Jun 12, 2018

hi thank you for your script, however the result is not what im up to, please see image below..Thank you really appreciate your help.

forum.jpg

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
Explorer ,
Jun 12, 2018 Jun 12, 2018

function Random(max){

      return Math.round(Math.random()*(max-1))+1

    }

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

        try{

        activeDocument.layers.opacity = Random(100)

        var Scale = Random(100)

        activeDocument.layers.resize(Scale, Scale)

        }catch(er){}

    }

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
New Here ,
Jun 12, 2018 Jun 12, 2018

awesome, sorry for being so demanding just one more please, would it be possible to set the minimum and maximum opacity and size...and only works for selected layers? Thank you very much

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
Explorer ,
Jun 12, 2018 Jun 12, 2018

function Random(min, max) {

    return Math.random() * (max - min) + min;

}

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

        try{

            if(activeDocument.layers.visible){

            activeDocument.layers.opacity = Random(20,100)

            var Scale = Random(20,100)

            activeDocument.layers.resize(Scale, Scale)

            }

            activeDocument.layers.visible = true

        }catch(er){}

    }

Now its working on VISIBLE layers.

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
New Here ,
Jun 12, 2018 Jun 12, 2018

Thanks you very much

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
New Here ,
Jun 12, 2018 Jun 12, 2018

sorryyyy last one, im trying my luck but not successful..i want to add also rotation..

  activeDocument.layers[i].rotate = Random(30,60

i tried that but didnt work

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
Explorer ,
Jun 12, 2018 Jun 12, 2018

function Random(min, max) {

    return Math.random() * (max - min) + min;

}

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

        try{

            if(activeDocument.layers.visible){

            activeDocument.layers.opacity = Random(20,100)

            var Scale = Random(20,100)

            activeDocument.layers.resize(Scale, Scale)

            activeDocument.layers.rotate(Random(0,360))

            }

            activeDocument.layers.visible = true

        }catch(er){}

    }

https://wwwimages2.adobe.com/content/dam/acom/en/devnet/photoshop/scripting/Photoshop-CS6-JavaScript...

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
New Here ,
Jun 12, 2018 Jun 12, 2018
LATEST

awesomeeee...Thanks a lot!

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
Explorer ,
Jun 12, 2018 Jun 12, 2018

function Random(max){

       return Math.round(Math.random()*(max-1))+1

    }

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

        try{

        activeDocument.layers.opacity = Random(100)

        activeDocument.layers.resize(Random(100), Random(100))

        }catch(er){}

    }

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