• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Why does this if else script fail?

Engaged ,
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

222

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

Community Expert , 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
...

Votes

Translate

Translate
Engaged ,
Dec 08, 2020 Dec 08, 2020

Copy link to clipboard

Copied

that last section was not meant to be commented out.

}else {

turnObjectOn()

Votes

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
Community Expert ,
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)

 

 

Votes

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

Copy link to clipboard

Copied

LATEST

Excellent, thank you. 

Votes

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