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

Find styled cell / Change row height

Explorer ,
Aug 28, 2010 Aug 28, 2010

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 (?)

TOPICS
Scripting
1.5K
Translate
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
Engaged ,
Aug 29, 2010 Aug 29, 2010

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

Translate
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 ,
Aug 29, 2010 Aug 29, 2010

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.

Translate
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
Engaged ,
Aug 29, 2010 Aug 29, 2010

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

Translate
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 ,
Aug 30, 2010 Aug 30, 2010
LATEST

Works OK, thanks a lot.

Translate
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