Why does this if else script fail?

Participant ,
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()
}
Adobe Community Professional
Correct answer by brianp311 | Adobe Community Professional

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)

 

 

TOPICS
Scripting

Views

46

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

Why does this if else script fail?

Participant ,
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()
}
Adobe Community Professional
Correct answer by brianp311 | Adobe Community Professional

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)

 

 

TOPICS
Scripting

Views

47

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

Copy link to clipboard

Copied

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
Reply
Loading...
Dec 08, 2020 0