Copy link to clipboard
Copied
Hi everyone
I've been playing around with scripting for a little while, however I don't quite understand what all is going on.
This is the script I've come up with:
#target photoshop
var s = app.activeDocument;
if(putName = "Flash 4" ){
app.doAction('4 Layer Flash', 'New Script Actions')
}
else {
if (putName = "Flash 3" ){
app.doAction('3 Layer Flash', 'New Script Actions')
}
else {
if (putName = "Flash 2" ){
app.doAction('2 Layer Flash', 'New Script Actions')
}
else {
if (putName = "No Flash 2" ){
app.doAction('2 Layer No Flash', 'New Script Actions')
}
}
}
}
What I was hoping this would do is run an action based off the top layers name which I would change to depending on how many layers I have and what I want it to do.
The issue i'm having is that even if I specify the name of the layer e.g No Flash 2 it would still run Flash 4.
Clearly I am doing something wrong.
Could anyone help me rectify where my mistakes are and what I should change?
Your script should be set up something like this:
#target photoshop
var doc = acitveDocument;
var putName = doc.layers[0].name;
switch (putName){
case 'Flash 4':
app.doAction('4 Layer Flash', 'New Script Actions');
break;
case 'Flash 3':
app.doAction('3 Layer Flash', 'New Script Actions');
break;
case 'Flash 2':
app.doAction('2 Layer Flash', 'New Script Actions');
break;
case 'Flash 1':
app.doAction('1 Layer Fla
...
Copy link to clipboard
Copied
you need to either use the else if statement or switch
if (some condition) {some code}
else if (a different condition){code}
else if (something else){code}
Or a switch:
Copy link to clipboard
Copied
Great thanks, I will give it a go.
If you dont mind me asking, which method would be preferrable?
Copy link to clipboard
Copied
I would use the switch method. I'm not at my computer, so it hard to say how to incorporate your script into a switch.
Copy link to clipboard
Copied
Okay thank you, will have a look at it.
If possible and if/when you have the time. Could you play around with it and see if you can get it to work.
Thanks for your time
Copy link to clipboard
Copied
I'm not too familiar with all the code, I normally take bits and pieces from already existing code, how would I incorporate it into what I already have?
Copy link to clipboard
Copied
Your script should be set up something like this:
#target photoshop
var doc = acitveDocument;
var putName = doc.layers[0].name;
switch (putName){
case 'Flash 4':
app.doAction('4 Layer Flash', 'New Script Actions');
break;
case 'Flash 3':
app.doAction('3 Layer Flash', 'New Script Actions');
break;
case 'Flash 2':
app.doAction('2 Layer Flash', 'New Script Actions');
break;
case 'Flash 1':
app.doAction('1 Layer Flash', 'New Script Actions');
break;
}//end switch
Copy link to clipboard
Copied
Thanks so much, I will give it a go