Skip to main content
Participant
October 1, 2018
Answered

Random opacity for multiple layers in layer group (or selected layers)

  • October 1, 2018
  • 3 replies
  • 1374 views

Hello,

Is it possible to randomly set a random opacity value to multiple layers at once?

I maganed to do it for one, but I would like to set an unique random value for each layer in a group, or selected layers if that is easier...

Many thanks in advance!

Barry

This topic has been closed for replies.
Correct answer barryd53273231

I did some research into scripting on my own... I think it's not possible to do it if layers have duplicate names, but if you have layers with unique ad logic names, you can do it in an easy for loop:

if (app.documents.length > 0) mainScript(); 

 

function mainScript() { 

    

for (i=1;i<=5;i++) {

     var myLayerName = "Layer " + i; 

     var myLayer = activeDocument.artLayers.getByName(myLayerName);

     myLayer.opacity = Math.floor (Math.random()*101);

     }

}

This gives a random opacity to Layer 1 through Layer 5.

It needs a bit more setup in the document itself, but that's okay for me.

3 replies

barryd53273231AuthorCorrect answer
Participant
October 3, 2018

I did some research into scripting on my own... I think it's not possible to do it if layers have duplicate names, but if you have layers with unique ad logic names, you can do it in an easy for loop:

if (app.documents.length > 0) mainScript(); 

 

function mainScript() { 

    

for (i=1;i<=5;i++) {

     var myLayerName = "Layer " + i; 

     var myLayer = activeDocument.artLayers.getByName(myLayerName);

     myLayer.opacity = Math.floor (Math.random()*101);

     }

}

This gives a random opacity to Layer 1 through Layer 5.

It needs a bit more setup in the document itself, but that's okay for me.

Kukurykus
Legend
October 3, 2018

You can use layers IDs that are unique. This way you avoid problem with duplicates.

Geppetto Luis
Legend
October 2, 2018

See if this is right for you

@JSXBIN@ES@2.0@MyBbyBnABMDbyBn0ABZEnACzBhLBCzBhKCEXzGjSjBjOjEjPjNDfjzEiNjBjUjIEfnfCzBhNFVzDiUiViGGfBVzDjNjJjOHfAnnnnVHfAnnACG4B0AhAH40BhAC0AzGiSjBjOjEjPjNIAFBaJbyKn0ABgKbyBn0ACOLbMn0ACJMnABXzHjPjQjBjDjJjUjZJfQzAKfXzGjMjBjZjFjSjTLfjzOjBjDjUjJjWjFiEjPjDjVjNjFjOjUMfjzBjJNfEjIfRCFdUFdjEffnfJNnASzFmOiYnViGmZOyBEjIfRCFdUFdjEffnftAXzHjWjJjTjJjCjMjFPfQKfXLfjMfjNfnJQnABXPfQKfXLfjMfjNfnctfABnzCjFjSQnnAjNfAXzGjMjFjOjHjUjIRfXLfjMfByBzBhcSABO40BiAABAKByB

Kukurykus
Legend
October 2, 2018

Are you embarassed of your own code you post it this way?

Geppetto Luis
Legend
October 2, 2018

Kukurykus

the code that I put is not mine already found encrypted

JJMack
Community Expert
Community Expert
October 2, 2018

I would think that you may be able to set multiply layer to have a  particular random opacity at once  not multiply different random opacities at once.

JJMack