Copy link to clipboard
Copied
The purpose of this is to toggle grey boxes. I created a script that works to turn on or off but if I put them in an if else they fail and don't work. Can someone tell me why?
var col = app.documents[0].colors.itemByName("InnerGlowGray")
if(!col.isValid)
col = app.documents[0].colors.add({colorValue:[0,0,0,40], name:"InnerGlowGray", space:ColorSpace.CMYK})
function turnTextBoxOff(){
app.selection[0].fillColor = ("None");
app.selection[0].transparencySettings.innerGlowSettings.applied = false;
};
function turnTextBoxOn(){
app.selection[0].fillColor = col;
app.selection[0].transparencySettings.innerGlowSettings.properties = {
applied: true,
opacity: 100,
spread: 0,
source: (InnerGlowSource.CENTER_SOURCED),
blendMode: (BlendMode.NORMAL),
opacity: 100,
spread : 0,
size : 0,
effectColor: col
}
};
function turnObjectOn(){
app.selection[0].transparencySettings.innerGlowSettings.properties = {
applied: true,
opacity: 100,
spread: 0,
source: (InnerGlowSource.CENTER_SOURCED),
blendMode: (BlendMode.NORMAL),
opacity: 100,
spread : 0,
size : 0,
effectColor: col
};
}
function turnObjOff(){
app.selection[0].transparencySettings.innerGlowSettings.applied = false;
}
if (app.selection[0] instanceof TextFrame && app.selection[0].transparencySettings.innerGlowSettings.applied = true){
turnTextBoxOff();
}else if (app.selection[0].transparencySettings.innerGlowSettings.applied = true){
turnObjOff();
}else if (app.selection[0] instanceof TextFrame && app.selection[0].transparencySettings.innerGlowSettings.applied = false){
turnTextBoxOn(); /*This is the section that fails
}else {
turnObjectOn()
}
You need to use boolean statements (double equal signs) in your if/else's. Chances are you are turning the applied setting to true by using the assignment operator (single equal sign), so it is never seeing it as false.
if (app.selection[0] instanceof TextFrame && app.selection[0].transparencySettings.innerGlowSettings.applied == true)
else if (app.selection[0].transparencySettings.innerGlowSettings.applied == true)
else if (app.selection[0] instanceof TextFrame && app.selection[0].transparen
...
Copy link to clipboard
Copied
that last section was not meant to be commented out.
}else {
turnObjectOn()
}
Copy link to clipboard
Copied
You need to use boolean statements (double equal signs) in your if/else's. Chances are you are turning the applied setting to true by using the assignment operator (single equal sign), so it is never seeing it as false.
if (app.selection[0] instanceof TextFrame && app.selection[0].transparencySettings.innerGlowSettings.applied == true)
else if (app.selection[0].transparencySettings.innerGlowSettings.applied == true)
else if (app.selection[0] instanceof TextFrame && app.selection[0].transparencySettings.innerGlowSettings.applied == false)
Copy link to clipboard
Copied
Excellent, thank you.