Copy link to clipboard
Copied
Hello,
I try to do with a script what InDesign (even CS5) cells styles doesn't : globally change row height on several styled cells at once.
But i'm just a graphic designer and new to ID scripting, so it's not easy…
I think first step could be : find all "myCellStyle" styled cells on the whole document.
I tried something like this but did'nt work (shows "Not found" alert) :
function findTable(obj) { while (obj.constructor.name != "Table") { obj = obj.parent; if (obj.constructor.name == "Application") { throw "Can't find table" } } return obj } var myTable = 0; if (app.documents.length > 0 && app.selection.length > 0) { myTable = findTable(app.selection[0]); } // Find styled celles formater if (myTable != 0) { if (myTable.cells.everyItem().appliedCellStyle == "myCellStyle") { alert("Found"); } else { alert("Not found"); } }
Second step could be : change rows height when containing found cells.
Thanks for your help that may interest other people too (?)
Copy link to clipboard
Copied
You can't search paragraph style with below code
if (myTable.cells.everyItem().appliedCellStyle == "myCellStyle") {
Here is working code on CS4
function findTable(obj) {
while (obj.constructor.name != "Table") {
obj = obj.parent;
if (obj.constructor.name == "Application") {
throw "Can't find table"
}
}
return obj
}
var myTable = 0;
if (app.documents.length > 0 && app.selection.length > 0) {
myTable = findTable(app.selection[0]);
//Find styles cells formater
if (myTable.constructor.name == "Table")
{
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences.appliedParagraphStyle = "myCellStyle";
var myCellStyle = myTable.findText();
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
}
if (myCellStyle.length>0)
{
for (var c = 0; c<myCellStyle.length; c++)
{
myCellStyle.parent.parentRow.height = "2p"; //Change row height as per your requirement
}
}
else{alert("Not found");}
}
Shonky
Copy link to clipboard
Copied
Hi Shonkyin,
Thanks for your answer but i don't understand why your script search for a paragraph style.
I try to change styled cells (with a cell style, not a paragraph style) height in tables.
I work with INDD CS5 and the script send me an error 30477.
Copy link to clipboard
Copied
Yes dear it is created for search paragraph style in table and change row height.
Try below one with Cell style
function findTable(obj) {
while (obj.constructor.name != "Table") {
obj = obj.parent;
if (obj.constructor.name == "Application") {
throw "Can't find table"
}
}
return obj
}
var myTable = 0;
if (app.documents.length > 0 && app.selection.length > 0) {
myTable = findTable(app.selection[0]);
}
// Find styled celles formater
if (myTable != 0) {
var myCellStylesLen = myTable.cells.length;
var myFound = 0;
for (var a=0; a<myCellStylesLen; a++)
{
if(myTable.cells.appliedCellStyle.name == "myCellStyle")
{
myTable.cells.parentRow.height = "2p"
myFound++
}
}
if (myFound == 0)
{
...
Shonky
Copy link to clipboard
Copied
Works OK, thanks a lot.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now