Copy link to clipboard
Copied
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.
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);
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
hi yeah the goal is if i have already created layers is to ramndomize each layer opacity and scale
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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){}
}
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thanks you very much
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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){}
}
Copy link to clipboard
Copied
awesomeeee...Thanks a lot!
Copy link to clipboard
Copied
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){}
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now