Why does this if else script fail?

Participant ,
Dec 08, 2020 Dec 08, 2020

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()
}
TOPICS
Scripting

Views

92

Likes

Translate

Translate

Report

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

Adobe Community Professional , Dec 08, 2020 Dec 08, 2020
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...

Likes

Translate

Translate
Participant ,
Dec 08, 2020 Dec 08, 2020

Copy link to clipboard

Copied

that last section was not meant to be commented out.

}else {

turnObjectOn()

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Dec 08, 2020 Dec 08, 2020

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)

 

 

Likes

Translate

Translate

Report

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
Participant ,
Dec 08, 2020 Dec 08, 2020

Copy link to clipboard

Copied

LATEST

Excellent, thank you. 

Likes

Translate

Translate

Report

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