Thread View: adobe.scripting.indesign
7 messages
7 total messages
Started by Kevin_Bird
Tue, 27 Jan 2009 11:51
Javascript to iterate over every cell in a table
Author: Kevin_Bird
Date: Tue, 27 Jan 2009 11:51
Date: Tue, 27 Jan 2009 11:51
18 lines
1435 bytes
1435 bytes
Hello experts I am importing XML tables into Indesign with attributes that specify the cell style, paragraph style, and character style. Indesign's rendering behaviour is quite odd as it displays some, but not all of the table correctly! When I click into a cell, the correct cell, paragraph and character styles are selected but the cell-style doesn't seem to be applied properly, especially the cell rules. If I click the cell style, then the rule is displayed. I need a work-round for this problem while Adobe are looking into it. Could someone write a Javascript that iterates through a table, cell by cell, finds the cellstyle that is currently applied and then re-applies that style? I'm hoping this will get round my problem. I currently have no experience with Javascript, so any help would be appreciated. I am running Indesign 5.0.4 Regards. -- Kevin
Re: Javascript to iterate over every cell in a table
Author: Dave_Saunders
Date: Tue, 27 Jan 2009 13:48
Date: Tue, 27 Jan 2009 13:48
41 lines
2553 bytes
2553 bytes
Bear in mind that every cell rule that is not on the edge of the table is shared. Thus, the look of any particular rule is determined by the order in which the cells are drawn, which is left to right then top to bottom.
Could this be the reason you're seeing what you're seeing?
Reapplying the cell styles might not do the job and the effect will be different depending on the order you do it.
I just created a pair of cell styles that won't live comfortably together. One applies a 1 point black rule left and right, the other applies a 0 point rule at left. These compete with each other. Apply them like a checkerboard and the result will depend on whether you go from top-left to bottom-right or the other direction.
This script demonstrates:
(function() {
if (app.documents.length > 0
&& app.selection.length > 0) {
var myTable = findTable(app.selection[0]);
if (myTable == null) { return }
var myStyles = myTable.cells.everyItem().appliedCellStyle;
for (var j = myStyles.length -1; j >= 0; j--) {
//~ for (var j = 0; myStyles.length > j; j++) {
if (myStyles[j].name != "None") {
myTable.cells[j].appliedCellStyle = myStyles[j];
}
}
}
}());
function findTable(obj) {
if (obj instanceof TextFrame) {
return obj.tables[0];
}
while (obj.constructor.name != "Table") {
obj = obj.parent;
if (obj.constructor.name == "Application") {
return null;
}
}
return obj
} // end findTable
Click in a table and run it. Change the loop to go the other way (just comment out the currently active for loop and activate the other one). If you get the same result, your cell styles are compatible and can coexist in adjacent cells, but if you don't the problem is your styles not InDesign behaving badly when rendering.
Dave
Re: Javascript to iterate over every cell in a table
Author: Kevin_Bird
Date: Tue, 27 Jan 2009 14:24
Date: Tue, 27 Jan 2009 14:24
18 lines
1074 bytes
1074 bytes
Hi Dave
Thanks for the quick response.
I did notice the way Indesign draws cell rules, but I don't think that is my problem, but I'd like to run your script to be sure.
I apologise, but my scripting knowledge is limited and I cannot get it to run within ESTK. The line below errors:
if (app.documents.length > 0 && app.selection.length > 0) {
saying 'undefined is not an object'
Could you please point me in the right direction?
Kind regards.
--
Kevin
Re: Javascript to iterate over every cell in a table
Author: Peter Kahrel
Date: Tue, 27 Jan 2009 14:51
Date: Tue, 27 Jan 2009 14:51
7 lines
1029 bytes
1029 bytes
Kevin, Something you try is this: force InDesign to redraw the screen, e.g. by toggling preview and normal screen modes. This might work as you say that merely clicking in a cell shows the lines. As to Dave's script, it may not run if you don't tell it to talk to InDesign. In the ESTK, look at the top left of the app. There are two dropdowns there; in the left one, select InDesign CS3. Peter
Re: Javascript to iterate over every cell in a table
Author: Dave_Saunders
Date: Tue, 27 Jan 2009 15:50
Date: Tue, 27 Jan 2009 15:50
7 lines
851 bytes
851 bytes
Hi Kevin, Peter beat me to it. When running from ESTK, make sure that the target application is InDesign CS3. I make that mistake about 20 times a week. Dave
Re: Javascript to iterate over every cell in a table
Author: Kevin_Bird
Date: Tue, 27 Jan 2009 16:43
Date: Tue, 27 Jan 2009 16:43
14 lines
1379 bytes
1379 bytes
Hi Peter & Dave Yes, targeting Indesign resolved the problem. Having run the script I can now see how Indesign renders the table, and yes, I have cellstyle rule conflicts. So, I see two work rounds. One, re-jig my cellstyles so there are no conflicts (see note below), or two, write a script that re-applies cellstyles to only styles that contains rules. Note: My table has 10 columns, the last row has one cell which spans all 10 columns and a rule is applied to the top of the cell. Applying the left-to-right top-to-bottom render, this rule should span across all 10 columns (as it is applied to the top of the spanned row), but only applies itself to the top of the first column, leaving the other nine blank. Any ideas? Kind regards. -- Kevin
Re: Javascript to iterate over every cell in a table
Author: Dave_Saunders
Date: Tue, 27 Jan 2009 17:06
Date: Tue, 27 Jan 2009 17:06
3 lines
800 bytes
800 bytes
Did you run the script counting up or down? For the script to apply that rule across the whole of the last row, it must happen after the styles were applied to the row above it. Dave
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads