Copy link to clipboard
Copied
Hello, I've been trying to change strokes across several pages without having to change styles and found this thread to be helpful: https://community.adobe.com/t5/indesign/script-to-find-change-stroke-in-tables/td-p/4315033?page=1
But when I was trying to test run the script, it returns the error message as shown below.
I have no idea what's going on. Could someone be kind enough to take a look at the code? Please help. Thank you so much!
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"] });
tbfStrk = measurementEditboxes.add({editValue:0.5});
}
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"] });
tbrStrk = measurementEditboxes.add({editValue:0.33});
}
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;
findStrk = tbfStrk.editValue;
findswatch = app.activeDocument.swatches.item(swf.selectedIndex);
changetint = tbr.editValue;
changeStrk = tbrStrk.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 && tab.cells.topEdgeStrokeWeight == findStrk)
{
s = true;
tab.cells.properties = {topEdgeStrokeColor:changeswatch, topEdgeStrokeTint:changetint, topEdgeStrokeWeight:changeStrk};
}
if (tab.cells.bottomEdgeStrokeColor == findswatch && tab.cells.bottomEdgeStrokeTint == findtint && tab.cells.bottomEdgeStrokeWeight == findStrk)
{
s = true;
tab.cells.properties = {bottomEdgeStrokeColor:changeswatch, bottomEdgeStrokeTint:changetint, bottomEdgeStrokeWeight:changeStrk};
}
if (tab.cells.leftEdgeStrokeColor == findswatch && tab.cells.leftEdgeStrokeTint == findtint && tab.cells.leftEdgeStrokeWeight == findStrk)
{
s = true;
tab.cells.properties = {leftEdgeStrokeColor:changeswatch, leftEdgeStrokeTint:changetint, leftEdgeStrokeWeight:changeStrk};
}
if (tab.cells.rightEdgeStrokeColor == findswatch && tab.cells.rightEdgeStrokeTint == findtint && tab.cells.rightEdgeStrokeWeight == findStrk)
{
s = true;
tab.cells.properties = {rightEdgeStrokeColor:changeswatch, rightEdgeStrokeTint:changetint, rightEdgeStrokeWeight:changeStrk};
}
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);
Seems like the code was broken when we shifted to the new forum software, i have fixed the code and it should work now
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 = percentComb...
Copy link to clipboard
Copied
Seems like the code was broken when we shifted to the new forum software, i have fixed the code and it should work now
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"] });
tbfStrk = measurementEditboxes.add({ editValue: 0.5 });
}
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"] });
tbrStrk = measurementEditboxes.add({ editValue: 0.33 });
}
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;
findStrk = tbfStrk.editValue;
findswatch = app.activeDocument.swatches.item(swf.selectedIndex);
changetint = tbr.editValue;
changeStrk = tbrStrk.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[t];
for (c = 0; c < tab.cells.length; c++) {
if (fills && tab.cells[c].fillColor == findswatch && tab.cells[c].fillTint == findtint) {
fillchanges++;
tab.cells[c].properties = { fillColor: changeswatch, fillTint: changetint };
}
if (strokes) {
s = false;
if (tab.cells[c].topEdgeStrokeColor == findswatch && tab.cells[c].topEdgeStrokeTint == findtint && tab.cells[c].topEdgeStrokeWeight == findStrk) {
s = true;
tab.cells[c].properties = { topEdgeStrokeColor: changeswatch, topEdgeStrokeTint: changetint, topEdgeStrokeWeight: changeStrk };
}
if (tab.cells[c].bottomEdgeStrokeColor == findswatch && tab.cells[c].bottomEdgeStrokeTint == findtint && tab.cells[c].bottomEdgeStrokeWeight == findStrk) {
s = true;
tab.cells[c].properties = { bottomEdgeStrokeColor: changeswatch, bottomEdgeStrokeTint: changetint, bottomEdgeStrokeWeight: changeStrk };
}
if (tab.cells[c].leftEdgeStrokeColor == findswatch && tab.cells[c].leftEdgeStrokeTint == findtint && tab.cells[c].leftEdgeStrokeWeight == findStrk) {
s = true;
tab.cells[c].properties = { leftEdgeStrokeColor: changeswatch, leftEdgeStrokeTint: changetint, leftEdgeStrokeWeight: changeStrk };
}
if (tab.cells[c].rightEdgeStrokeColor == findswatch && tab.cells[c].rightEdgeStrokeTint == findtint && tab.cells[c].rightEdgeStrokeWeight == findStrk) {
s = true;
tab.cells[c].properties = { rightEdgeStrokeColor: changeswatch, rightEdgeStrokeTint: changetint, rightEdgeStrokeWeight: changeStrk };
}
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);
Please update if it works so that we can post the correction on the original thread as well
-Manan
Copy link to clipboard
Copied
Hi Manan, thank you so much for your help! It worked beautifully. Thank you thank you thank you!!!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more