Skip to main content
Inspiring
July 16, 2019
Answered

how define if (myCells.fillColor = "Black")

  • July 16, 2019
  • 4 replies
  • 591 views

Hi experts,

my script like this:

var myDoc =  app.activeDocument;

var myCells = myDoc.stories.everyItem().tables.everyItem().cells.everyItem();

if (myCells.fillColor = "Black") {

    myCells.fillColor = "PANTONE 300 C"

    }

aim to fine the cells if fillColor = "Black",

then change the fillColr = "PANTONE 300 C"

but not working,

could someone please show me how.

thanks

regard

John

This topic has been closed for replies.
Correct answer Manan Joshi

Try the following

var myDoc =  app.activeDocument;

var myCells = myDoc.stories.everyItem().tables.everyItem().cells.everyItem().getElements()

for(var i = 0; i < myCells.length; i++)

{

    if (myCells.fillColor.name == "Black") {

          myCells.fillColor = "PANTONE 300 C"

    }

}

-Manan

4 replies

JohnwhiteAuthor
Inspiring
July 16, 2019

thank you Man,

thank so much.

John

JohnwhiteAuthor
Inspiring
July 16, 2019

thank you Man,

but still not working.

thanks

regard

John

Manan JoshiCommunity ExpertCorrect answer
Community Expert
July 16, 2019

Try the following

var myDoc =  app.activeDocument;

var myCells = myDoc.stories.everyItem().tables.everyItem().cells.everyItem().getElements()

for(var i = 0; i < myCells.length; i++)

{

    if (myCells.fillColor.name == "Black") {

          myCells.fillColor = "PANTONE 300 C"

    }

}

-Manan

-Manan
Sunil Yadav
Legend
July 16, 2019

In IF condition, there can't be single Equal to sign (=).

For comparison you have to use two equal just like this (myCells.fillColor == "Black")

If you are doing like this (myCells.fillColor = "Black") , this doesn't mean you are comparing, this single Equal sign is for assigning the value.

Best

Sunil

Community Expert
July 16, 2019

In order to compare values you need to use == operator, = is meant for assignment. The correct if statement for you would be

if(myCells.fillColor == "Black")

-Manan

-Manan