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

Change color in tables via "Find/Change"

Explorer ,
Feb 27, 2024 Feb 27, 2024

Copy link to clipboard

Copied

I have these tables throuout a catalogue of approx 300 pages. I need to change the grey from a 40% of a defined grey colour to 100% of a new beige colour. 

I have tried combining the 2 swatches, but I end op with the beige in 40% instead of 100%. I have tried Find/Change colour, but that did not change the colour in the table. It worked in all of the rest of the catalogues, just not in the tables.

Is there a way to use Find/Change or do I need to manually change the colour from 40% to 100% in every tables?

TOPICS
How to

Views

307

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

Participant , Feb 28, 2024 Feb 28, 2024

Gotcha — 

 

app.doScript(Main, undefined, undefined, UndoModes.ENTIRE_SCRIPT,"Run Script");
function Main(){

    //Declare variables
    var myDoc = app.activeDocument;
    var beigeSwatch = myDoc.swatches.itemByName("Beige");
    var myCells = myDoc.stories.everyItem().tables.everyItem().cells.everyItem().getElements();

    for (var cellCount = 0; cellCount < myCells.length; cellCount++) {
        var myCell = myCells[cellCount];

        //If cell fill tint is 40%, apply new fill color
       
...

Votes

Translate

Translate
Participant ,
Feb 28, 2024 Feb 28, 2024

Copy link to clipboard

Copied

I'm assuming you do not have a cell style applied to those cells? (That would be the ideal way to set up these types of tables in the future.)

 

The following script will find all cells with a background tint of 40% (no matter what color) and apply the color swatch called "Beige". So before you run this script, you will need to make sure you have created a "Beige" color swatch, and do not save it inside any swatch folder.

app.doScript(Main, undefined, undefined, UndoModes.ENTIRE_SCRIPT,"Run Script");
function Main(){

    //Declare variables
    var myDoc = app.activeDocument;
    var beigeSwatch = myDoc.swatches.itemByName("Beige");

    // loop pages
    for (var pageCount = 0; myDoc.pages.length > pageCount; pageCount++) {
        var myPage = myDoc.pages[pageCount];

        // loop textframes
        for (var textFrameCount = 0; textFrameCount < myPage.textFrames.length; textFrameCount++) {
            var myTextFrame = myPage.textFrames[textFrameCount];

            // loop tables
            for (var tableCount = 0; tableCount < myTextFrame.tables.length; tableCount++) {
                var myTable = myTextFrame.tables[tableCount];

                // loop cells 
                for (var cellCount = 0; cellCount < myTable.cells.length; cellCount++) {
                    var myCell = myTable.cells[cellCount];

                    //If cell fill color is black, apply new fill color
                    if (myCell.fillTint==40) {
                        myCell.fillColor = beigeSwatch;
                        myCell.fillTint = 100;
                    }
                }
            }
        }
    }
}

If your 40% grey is actually saved as its own swatch (with the tint percentage defined as part of the swatch), I'll need to adjust the script. Just let me know if this doesn't work!

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 ,
Feb 28, 2024 Feb 28, 2024

Copy link to clipboard

Copied

@danaken3

 

In case of doing something on ALL Text objects - you should NEVER iterate through TextFrames collection of the Document - you should iterate through Stories collection of the document - and then texts[0] if you want to make it more universal.

 

Also, you completely unnecessarily are looping through Pages in the most outside loop - TextFrames are also a collection of the Document.

 

Then, instead of those multiple loops - you could get a collection of all cells:

 

var myCells = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements()

 

Then iterate through this. 

 

But, as someone pointed out recently - you would have to do a separate getElements() on footnotes, etc. 

 

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
Participant ,
Feb 28, 2024 Feb 28, 2024

Copy link to clipboard

Copied

Gotcha — 

 

app.doScript(Main, undefined, undefined, UndoModes.ENTIRE_SCRIPT,"Run Script");
function Main(){

    //Declare variables
    var myDoc = app.activeDocument;
    var beigeSwatch = myDoc.swatches.itemByName("Beige");
    var myCells = myDoc.stories.everyItem().tables.everyItem().cells.everyItem().getElements();

    for (var cellCount = 0; cellCount < myCells.length; cellCount++) {
        var myCell = myCells[cellCount];

        //If cell fill tint is 40%, apply new fill color
        if (myCell.fillTint==40) {
            myCell.fillColor = beigeSwatch;
            myCell.fillTint = 100;
        }
    }
}

 

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
Explorer ,
Feb 28, 2024 Feb 28, 2024

Copy link to clipboard

Copied

LATEST

Thank you both so much. It worked and saved me hours and hours of work. I am very grateful for your help.

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