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

Search/replace color cell stroke

Explorer ,
May 23, 2019 May 23, 2019

Copy link to clipboard

Copied

I need to find (and replace) where and if a specific color is applied, even in the strokes of a cell/table (which I can't do).

Does a script already exist to do this?

Thanks

TOPICS
Scripting

Views

1.0K

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 ,
May 23, 2019 May 23, 2019

Copy link to clipboard

Copied

I've found this thread, the script works, but only on single pages.

Is anyone able to modify it to work on a document with multiple pages?

Quick edits in multiple tables/multiple files

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 ,
May 23, 2019 May 23, 2019

Copy link to clipboard

Copied

Why do you think that this would work on single pages only?

I briefly looked into the code and can see that all stories of the document are targeted:

st = app.activeDocument.stories;

And here the loop goes through all tables of a story in the document:

tb = st.tables;

Regards,
Uwe

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 ,
May 24, 2019 May 24, 2019

Copy link to clipboard

Copied

Many thanks for the reply.

I don't know much about scripts.

Can you help me modify those strings correctly?

---------

I found another thread, but I don't want to change also the stroke thickness, so I've copied a part of that script into the one I had already tried. Now it seems to work.

The other thread is this: Script to find/change stroke in tables

And the good part is this:

tb = app.activeDocument.stories.everyItem().tables.everyItem().getElements();   

for (t=tb.length-1; t>=0; t--)   

{   

  tab = tb;   

  for (c=0; c<tab.cells.length; c++)   

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 ,
May 24, 2019 May 24, 2019

Copy link to clipboard

Copied

//DESCRIPTION:Change Table Fills and Strokes 

// Jongware, 18-Jul-2010 

myDialog = app.dialogs.add ({name:"Recolor Tables",canCancel:true}); 

swatchlist = app.activeDocument.swatches.everyItem().name; 

with (myDialog) 

with (dialogColumns.add()) 

  with (borderPanels.add()) 

  { 

   staticTexts.add ({staticLabel:"Find"}); 

   swf = dropdowns.add ({stringList:swatchlist, selectedIndex:0}); 

   tbf = percentComboboxes.add({editValue:100, largeNudge:10, stringList:["25", "50", "75", "100"] }); 

  } 

  with (borderPanels.add()) 

  { 

   staticTexts.add ({staticLabel:"Replace"}); 

   swr = dropdowns.add ({stringList:swatchlist, selectedIndex:0}); 

   tbr = percentComboboxes.add({editValue:100, largeNudge:10, stringList:["25", "50", "75", "100"] }); 

  } 

  with (borderPanels.add()) 

  { 

   dostrokes = checkboxControls.add({staticLabel:"Change strokes", checkedState:true}); 

   dofills = checkboxControls.add({staticLabel:"Change fills", checkedState:true}); 

  } 

if (!myDialog.show() || !(dostrokes.checkedState || dofills.checkedState)) 

myDialog.destroy(); 

exit(0); 

findtint = tbf.editValue; 

findswatch = app.activeDocument.swatches.item(swf.selectedIndex); 

changetint = tbr.editValue; 

changeswatch = app.activeDocument.swatches.item(swr.selectedIndex); 

strokes = dostrokes.checkedState; 

fills = dofills.checkedState; 

fillchanges = 0; 

strokechanges = 0;   

tb = app.activeDocument.stories.everyItem().tables.everyItem().getElements();   

for (t=tb.length-1; t>=0; t--)   

{   

  tab = tb;   

  for (c=0; c<tab.cells.length; c++)   

  {   

   if (fills && tab.cells.fillColor == findswatch && tab.cells.fillTint == findtint)   

   {   

    fillchanges++;   

    tab.cells.properties = {fillColor:changeswatch, fillTint:changetint};   

   }   

   if (strokes)   

   {   

    s = false;   

    if (tab.cells.topEdgeStrokeColor == findswatch && tab.cells.topEdgeStrokeTint == findtint)   

    {   

     s = true;   

     tab.cells.properties = {topEdgeStrokeColor:changeswatch, topEdgeStrokeTint:changetint};   

    }   

    if (tab.cells.bottomEdgeStrokeColor == findswatch && tab.cells.bottomEdgeStrokeTint == findtint)   

    {   

     s = true;   

     tab.cells.properties = {bottomEdgeStrokeColor:changeswatch, bottomEdgeStrokeTint:changetint};   

    }   

    if (tab.cells.leftEdgeStrokeColor == findswatch && tab.cells.leftEdgeStrokeTint == findtint)   

    {   

     s = true;   

     tab.cells.properties = {leftEdgeStrokeColor:changeswatch, leftEdgeStrokeTint:changetint};   

    }   

    if (tab.cells.rightEdgeStrokeColor == findswatch && tab.cells.rightEdgeStrokeTint == findtint)   

    {   

     s = true;   

     tab.cells.properties = {rightEdgeStrokeColor:changeswatch, rightEdgeStrokeTint:changetint};   

    }   

    if (s)   

     strokechanges++;  

  } 

}  

ch = "No changes made"; 

if (fillchanges) 

ch = fillchanges+" fills changed"; 

if (strokechanges) 

  ch += "\n"+strokechanges+" strokes changed"; 

} else if (strokechanges) 

  ch = strokechanges+" strokes changed"; 

alert (ch);

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 ,
May 24, 2019 May 24, 2019

Copy link to clipboard

Copied

Hi bebez71 ,

your last reply was empty ?!

FWIW: you can get all cells of all tables of all stories of a document like that:

var tableCellsArray = app.documents[0].stories.everyItem().

tables.everyItem().cells.everyItem().getElements();

var tableCellsArrayLength = tableCellsArray.length;

for( var n=0; n<tableCellsArrayLength; n++ )

{

var currentCell = tableCellsArray;

/* Do something with a single cell here */

};

Regards,
Uwe

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 ,
May 24, 2019 May 24, 2019

Copy link to clipboard

Copied

Laubender​

I don't know why my previous reply was empty.

I've put an HTML table like yours...

Now I'm not at work and I can't fix it.

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 ,
May 25, 2019 May 25, 2019

Copy link to clipboard

Copied

Hi bebez71 ,

to present formatted JavaScript code with syntax highlighting use the Advanced Editor feature in the forum.

Select your code and go to  Insert >> Syntax Highlighting > javascript

( You have to scroll a bit down to see that option )

Regards,
Uwe

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 ,
May 27, 2019 May 27, 2019

Copy link to clipboard

Copied

Thanks Laubender​

Here the code

//DESCRIPTION:Change Table Fills and Strokes 

// Jongware, 18-Jul-2010 

myDialog = app.dialogs.add ({name:"Recolor Tables",canCancel:true}); 

swatchlist = app.activeDocument.swatches.everyItem().name; 

with (myDialog) 

with (dialogColumns.add()) 

  with (borderPanels.add()) 

  { 

   staticTexts.add ({staticLabel:"Find"}); 

   swf = dropdowns.add ({stringList:swatchlist, selectedIndex:0}); 

   tbf = percentComboboxes.add({editValue:100, largeNudge:10, stringList:["25", "50", "75", "100"] }); 

  } 

  with (borderPanels.add()) 

  { 

   staticTexts.add ({staticLabel:"Replace"}); 

   swr = dropdowns.add ({stringList:swatchlist, selectedIndex:0}); 

   tbr = percentComboboxes.add({editValue:100, largeNudge:10, stringList:["25", "50", "75", "100"] }); 

  } 

  with (borderPanels.add()) 

  { 

   dostrokes = checkboxControls.add({staticLabel:"Change strokes", checkedState:true}); 

   dofills = checkboxControls.add({staticLabel:"Change fills", checkedState:true}); 

  } 

if (!myDialog.show() || !(dostrokes.checkedState || dofills.checkedState)) 

myDialog.destroy(); 

exit(0); 

findtint = tbf.editValue; 

findswatch = app.activeDocument.swatches.item(swf.selectedIndex); 

changetint = tbr.editValue; 

changeswatch = app.activeDocument.swatches.item(swr.selectedIndex); 

strokes = dostrokes.checkedState; 

fills = dofills.checkedState; 

fillchanges = 0; 

strokechanges = 0;   

tb = app.activeDocument.stories.everyItem().tables.everyItem().getElements();   

for (t=tb.length-1; t>=0; t--)   

{   

  tab = tb;   

  for (c=0; c<tab.cells.length; c++)   

  {   

   if (fills && tab.cells.fillColor == findswatch && tab.cells.fillTint == findtint)   

   {   

    fillchanges++;   

    tab.cells.properties = {fillColor:changeswatch, fillTint:changetint};   

   }   

   if (strokes)   

   {   

    s = false;   

    if (tab.cells.topEdgeStrokeColor == findswatch && tab.cells.topEdgeStrokeTint == findtint)   

    {   

     s = true;   

     tab.cells.properties = {topEdgeStrokeColor:changeswatch, topEdgeStrokeTint:changetint};   

    }   

    if (tab.cells.bottomEdgeStrokeColor == findswatch && tab.cells.bottomEdgeStrokeTint == findtint)   

    {   

     s = true;   

     tab.cells.properties = {bottomEdgeStrokeColor:changeswatch, bottomEdgeStrokeTint:changetint};   

    }   

    if (tab.cells.leftEdgeStrokeColor == findswatch && tab.cells.leftEdgeStrokeTint == findtint)   

    {   

     s = true;   

     tab.cells.properties = {leftEdgeStrokeColor:changeswatch, leftEdgeStrokeTint:changetint};   

    }   

    if (tab.cells.rightEdgeStrokeColor == findswatch && tab.cells.rightEdgeStrokeTint == findtint)   

    {   

     s = true;   

     tab.cells.properties = {rightEdgeStrokeColor:changeswatch, rightEdgeStrokeTint:changetint};   

    }   

    if (s)   

     strokechanges++;  

  } 

}  

ch = "No changes made"; 

if (fillchanges) 

ch = fillchanges+" fills changed"; 

if (strokechanges) 

  ch += "\n"+strokechanges+" strokes changed"; 

} else if (strokechanges) 

  ch = strokechanges+" strokes changed"; 

alert (ch);

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 ,
May 27, 2019 May 27, 2019

Copy link to clipboard

Copied

LATEST

Unfortunately last script also has a limit, it doesn't seem to work if there are merged cells.

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 ,
May 24, 2019 May 24, 2019

Copy link to clipboard

Copied

Hi,

You should be able to make it one loop by doing something like

allCells = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();

for ( c =0; c< allCells.length; c++)

{

//// your code here

Regards

Malcolm

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