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
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?
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
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++)
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);
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
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.
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
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);
Copy link to clipboard
Copied
Unfortunately last script also has a limit, it doesn't seem to work if there are merged cells.
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