Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
0

Random blend mode

Advocate ,
Nov 19, 2018 Nov 19, 2018

I would like to use the randon blend mode method on the selected level

I put this together

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

blendMode = Math.random();

where am I wrong?

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

correct answers 1 Correct answer

Community Expert , Nov 19, 2018 Nov 19, 2018

Try

blendMode = blendModes[Math.floor(Math.random()*4)];

Have fun

Translate
Adobe
Community Expert ,
Nov 19, 2018 Nov 19, 2018

Try

blendMode = blendModes[Math.floor(Math.random()*4)];

Have fun

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 ,
Nov 19, 2018 Nov 19, 2018

I tried but it does not work

this and what I did.

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

blendMode = blendModes[Math.floor(Math.random()*4)]; 

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 ,
Nov 19, 2018 Nov 19, 2018

add alert(blendMode)

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
Contributor ,
Nov 19, 2018 Nov 19, 2018

Don't forget to set it to a layer

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

activeDocument.activeLayer.blendMode = blendModes[Math.floor(Math.random()*4)]; 

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
Engaged ,
Jun 03, 2021 Jun 03, 2021

I run the snipt and it works well. Is it posible to chenge the random method to cycle the blend modes in sequential order?

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 ,
Jun 03, 2021 Jun 03, 2021

Take out the Math random Spartans just loop through the array.

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
Engaged ,
Jun 03, 2021 Jun 03, 2021

I am not sure what the spartas are. When I remove the *4, or the Math.random() method, the script does not run.

How do I remove the Math random spartans?

 

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

activeDocument.activeLayer.blendMode = blendModes[Math.floor(Math.random()*4)];
 
for (var i=0; i<blendModes.length; i++)
{
alert(activeDocument.activeLayer.blendMode);
}

 
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 ,
Jun 03, 2021 Jun 03, 2021

If you just loop through the blend modes on the same layer, all you will get is the last blend mode, when the script is done. What do you want to do? To select a particular band mode in your loop you want:

 

activeDocument.activeLayer.blendMode = blendModes[i];

 

 

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
Engaged ,
Jun 03, 2021 Jun 03, 2021

Thanks for your help! I am trying to loop throug the blend modes in the array to toogle between the Normal and Multiplie blend modes.  When the script runs,  it sets the active layer blend mode to NORMAL if it is MULTIPLE. And NORMAL if the active layer blend mode is MULTIPLE. 

Do I need a conditonal satament to check the acltive layer blend mode?

 

var blendModes = [BlendMode.NORMAL, BlendMode.MULTIPLY];
 
activeDocument.activeLayer.blendMode = blendModes[i];
 
for (var i=0; i<blendModes.length; i++)
{
alert(activeDocument.activeLayer.blendMode);
}

 

 

 

 

 

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 ,
Jun 03, 2021 Jun 03, 2021

It's better if you said at beginning what you exactly wish:

 

aL.blendMode = (bm = BlendMode)[({NORMAL: 'MULTIPLY', MULTIPLY: 'NORMAL'})
[unescape((aL = activeDocument.activeLayer).blendMode).split(bm + '.')[1]]]

 

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
Engaged ,
Dec 03, 2021 Dec 03, 2021

I undesrstand the snipe only works when the layers are in NORMAL and MULTIPLY blend modes.

When I try to change the blend modes to NORMAL and COLOR I get an error alert.

Error: Invalid enumartion vlaue

What needs to change on the code so that the it works with the NORMAL and COLOR  blend modes?

Screen Shot 2021-12-03 at 9.09.44 AM.png

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 ,
Dec 03, 2021 Dec 03, 2021

COLORBLEND

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
Engaged ,
Dec 03, 2021 Dec 03, 2021

Thanks for your quick response. This is not working in a mac system.  Am I missing something?

aL.blendMode = (bm = BlendMode)[({NORMAL: 'COLORBLEND', COLORBLEND: 'NORMAL'})
[unescape((aL = activeDocument.activeLayer).blendMode).split(bm + '.')[1]]]
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 ,
Dec 03, 2021 Dec 03, 2021

I tried it in CS6 and PS 2020 on no background layer. Maybe change unescape to String, and use one line of that code instead of current two. Set layer to Normal or Color blend mode.

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
Engaged ,
Dec 03, 2021 Dec 03, 2021

Do you mean one continuous line for the code instead of two lines?

aL.blendMode = (bm = BlendMode)[({NORMAL: 'COLORBLEND', COLORBLEND: 'NORMAL'})[String((aL = activeDocument.activeLayer).blendMode).split(bm + '.')[1]]]
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 ,
Dec 04, 2021 Dec 04, 2021

Yes. Didn't multiply / normal version work for you?

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
Engaged ,
Dec 04, 2021 Dec 04, 2021
LATEST

Got it I wanted to make ssure I undesrtand what to do. The code works with the String change in PS2022 Tested succesfully with diffrent blend mode pairs. Many thansk for your generous help!

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
Engaged ,
Jun 03, 2021 Jun 03, 2021

Thank you! The last snipet works well when the active layer is in Normal or Mutiple mode.

 

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 ,
Jun 03, 2021 Jun 03, 2021

That's right. There had not to be other blendings, so it works only for these two.

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 ,
Jun 03, 2021 Jun 03, 2021

Can you tell me if this solution works on Macintosh: May 31, 2021

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 ,
Jun 03, 2021 Jun 03, 2021
bm = ['NORMAL', 'SCREEN', 'MULTIPLY', 'OVERLAY']; while(bm.length)
	activeDocument.activeLayer.blendMode = BlendMode[bm.shift()]
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
Engaged ,
Jun 03, 2021 Jun 03, 2021

This snipet does not work on Mac system. It chenges the blend mode of the active layer from Normal to Overlay and persits in Overlay.

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 ,
Jun 03, 2021 Jun 03, 2021

So as intended due to your original description before specifying what you exactly need.

A working code for you is the other I left later. As to Mac I asked of code in linked topic.

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