CreativePro Forum
Join our community of graphic designers, publishers, and production artists from around the world. Our members-only forum is a great place to discuss challenges and find solutions!
- You must be logged in to reply to this topic.Login
Define table row heights, column widths in styles somehow?
- This topic has 27 replies, 9 voices, and was last updated 13 years, 4 months ago by
Al.
-
AuthorPosts
-
-
May 20, 2010 at 8:30 pm #52812
Roland
MemberThe catalog I'm working on now is turning out to be a huge PITA thanks to my client changing his mind several times in a row. I've now come to the point where I have some 40 pages with several tables on each that have had a word in the header row changed, and of course now nothing fits anymore.
Am I going to have to go through all pages, selecting the tables one at a time to change the header row's height, or is there a <insert lisp> super secret table cell style setting </end lisp> I'm not seeing that will let me do this in one go?
-
May 20, 2010 at 10:43 pm #52813
Theunis De Jong
MemberIt would seem you set your row heights to be of a fixed height. In hindsight, you would have been better off if you used the “Automatic” setting, together with the right cell insets on top and bottom, to get the height you wanted. Ahhh … the benefits of hindsight :-)
A simple javascript can set all header row heights to the same value.
The downside is, well, it would set all header row heights to the same value. If you have a few tables where this should not happen, you'd have to run the script and then restore these tables. If you have a mixed set, where some need changing and others do not, a script cannot help at all …
That header: is that just one row? Is it just the top row for each table, or did you actually converted them to Header Rows?
-
May 20, 2010 at 10:53 pm #52814
David BlatnerKeymasterYeah, it's frustrating that you cannot set “geometry” (including how tall or wide a row or column should be) in styles.
I have the same frustration with object styles… you cannot set object size there, either.
-
May 21, 2010 at 12:46 am #52815
Roland
MemberUnfortunately I set them to be header rows and indeed a fixed size. Going through them one by one to set them to “at least” works but it so darned time consuming I might be better off just making one new table with the correct settings, copying & pasting it plenty of times and then copying & pasting the contents back in.
It's a 3-day weekend over here, so I'll get to it on Tuesday.
I used the Bug/Feature Report form on Adobe's site to request a width/height option in the styles dialog boxes, but if I'm the only one who asks for these sorts of things, I doubt it'll ever be added, no matter how useful it may be or how many people want it (the form is so well hidden I had to Google for it).
-
May 21, 2010 at 1:00 am #52816
Theunis De Jong
MemberOkay — perhaps this javascript is all you need. It will change the first row of each table in your entire document to the height you specify (in regular shorthand notation, e.g., “0.125in” or “1.2cm”). Fortunately — or not –, it doesn't matter whether it's a “header” row or a regular one.
Pay attention now, because last time I inserted a script of this length it was completely overlooked. (…)
Ready?
app.activeDocument.stories.everyItem().tables.everyItem().rows[0].height = “12mm”; // <- Change me!
Okay — that was it. Don't let its length fool you; a lot of thought went into it :-)
Copy, paste into a plain text editor (Notepad, Textedit — in plain text mode — or Adobe's own ESTK Editor), and save as “ChangeFirstRowsTo20mm.jsx” into your User Scripts folder. You don't have to do anything but double-click the script and sit back.
(Given the speed it works at, you might not even have time to sit back.)
-
May 21, 2010 at 3:43 am #52817
erickp
MemberDid I mention no feature enhancements for Tables in InDesign CS5? Must be the bastard son of features within ID, since they didn't seem to touch it at all. I suppose it must be perfect as is. ;-)
-
May 24, 2010 at 10:09 pm #52818
Roland
MemberAnother perfect script, Jongware. 10mm did the job :)
erickp, either that or nobody uses tables :)
Maybe I ought to add some animations to this catalog's file if the tables end up being too much of a hassle after all. I bet my client would love animation in his printed catalogs…. -
May 24, 2010 at 10:29 pm #52819
Anonymous
InactiveI would really prefer if there was a fit columns function, or the ability to double click to resize cells to fit.
Tables are a bit clunky in InDesign.
-
May 27, 2010 at 3:15 pm #52820
Nadya Miloserdova
MemberA big WOW!
-
May 30, 2010 at 4:56 pm #52821
Roland
MemberOf course clients keep changing their minds, so I've had to adjust the script so it can change the width of a column in all tables. Turns out it takes only two words to be changed, along with the values of course:
app.activeDocument.stories.everyItem().tables.everyItem().rows[0].height = “12mm“;
app.activeDocument.stories.everyItem().tables.everyItem().columns[4].width = “6mm“;It doesn't change the fact better planning probably wouldn't have made the scripts necessary at all, but it looks like most of the data has changed (gotta love “final versions” changing several times) so I'll have to start copying data from scratch anyway.
-
June 3, 2010 at 5:09 pm #52822
seb400
MemberThis little script will prove invaluable for me!
I have amended above suggestions to give me the column widths for a particular table.
However I would like to be able to define a 'row depth' for all the remaining rows of a table below the two specified rows.
app.activeDocument.stories.everyItem().tables.everyItem().rows[0].height = “15mm”;
app.activeDocument.stories.everyItem().tables.everyItem().rows[1].height = “8mm”;app.activeDocument.stories.everyItem().tables.everyItem().columns[0].width = “8mm”;
app.activeDocument.stories.everyItem().tables.everyItem().columns[1].width = “36mm”;
app.activeDocument.stories.everyItem().tables.everyItem().columns[2].width = “37mm”;
app.activeDocument.stories.everyItem().tables.everyItem().columns[3].width = “7.5mm”;
app.activeDocument.stories.everyItem().tables.everyItem().columns[4].width = “7.5mm”;
app.activeDocument.stories.everyItem().tables.everyItem().columns[5].width = “7.5mm”;
app.activeDocument.stories.everyItem().tables.everyItem().columns[6].width = “7.5mm”;
app.activeDocument.stories.everyItem().tables.everyItem().columns[7].width = “7.5mm”;
app.activeDocument.stories.everyItem().tables.everyItem().columns[8].width = “7.5mm”;MTIA Steve
-
June 3, 2010 at 7:21 pm #52823
Theunis De Jong
MemberHi Steve, and welcome to the wonderful world of scripting!
If you want to change “rows 2 to x“, normally you would have to 'manually' loop over these rows, and to do that, you'd have to manually loop over all tables, and to do that, well, you'd have to manually loop over all stories … Using the fast everyItem() function avoids all this work, but — it can only work on every item, not something like 'from row 2 to the end' (hence the name :-D ).
So you have no choice, other than using the much slower loops? Sure you have! You can set all rows of all tables to your 'remaining' height value, and then change only the 1st and 2nd rows' height.
Add this line before your first one, and you should be done:
app.activeDocument.stories.everyItem().tables.everyItem().rows.everyItem().height = “20mm”;
(replacing the 20 mm with the height you need).
-
June 3, 2010 at 7:37 pm #52824
seb400
MemberThanks Jongware!
As much as I'm struggling with (basic) scripting, I must admit to enjoying that sort of simple logic that just doesn't feature in my 'designer' mindset
Steve
-
August 27, 2010 at 10:53 pm #52825
avanti
ParticipantHi everybody,
First, thanks for your very interesting and comprehensive contributions.
I found and used the Jongware script above (app.activeDocument.stories.everyItem().tables.everyItem().rows[0].height = “12mm“;) to do what InDesign, even CS5 version, doesn't provide : cells dimensions in styles.
But i'd like to go a little further and change only particular styled cells height, not all first, second… rows.
I tried to insert appliedStyle in the script like that :
(app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().appliedStyle = “myCellStyle”.height = “12mm“;)Obviously, i'm so new to script, it doesn't work and i don't really understand what i do.
Please, can you guide me ?
Thanks in advance.
Sorry for my poor english. -
August 28, 2010 at 3:23 am #52826
Theunis De Jong
MemberJavascript is missing a construct that is available in Applescript: the whose command. whose selects from an array only the elements that have a certain value. Since you don't want to apply your change to every cell, which is what everyItem selects, you'll have to get 'everything', then loop over the result, applying your height only to cells with the right name.
This seems to work (since it's no longer a single command, Undo undoes it one at a time):
cellarray = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();
for (a=0; a<cellarray.length; a++)
if (cellarray[a].appliedCellStyle.name == “myCellStyle”) // <- Cell Style Name!
cellarray[a].height = “12mm”; -
August 28, 2010 at 4:30 am #52827
avanti
ParticipantThanks a lot for your clear and quick answer Jongware, it perfectly works !
Do you think the same type of script could be “undone” in 1 time with Applescript (rather than 1 “Undo” per modification with Javascript) ?
-
August 28, 2010 at 4:47 am #52828
Theunis De Jong
MemberThat's strange — I can't get it not to work (locked story, locked layer, header rows …). There must be Something Unexpected™ in your tables.
Can you try this? It counts the number of changes made.
cellarray = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();
changed = 0;
for (a=0; a<cellarray.length; a++)
if (cellarray[a].appliedCellStyle.name == “myCellStyle”) <- Cell Style Name
cellarray[a].height = “12mm”, changed++;
alert (changed+” change(s) made”); -
August 28, 2010 at 4:55 am #52829
avanti
ParticipantSorry Jongware, it's my (huge) mistake : I took a paragraph style for a cell style (“Booooooo, looser !!!!!”).
Your script perfectly works (i just edited my post).
Sorry and thanks again.
-
August 28, 2010 at 5:03 am #52830
Theunis De Jong
Member(Achh! Reply was to previous replay ;))
Yes, I suspect writing it as one single AS command allows you to Undo it at once. However, Me ≠ AppleScript.
There is also a way to encapsulate an entire Javascript into one “undo” command — hold on while I look up how that was done.
(.. insert elevator muzak here ..)
There we go:
cellStyleName = “myCellStyle”;
newHeight = “12mm”;app.doScript (sizeRows, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, 'Undo Resize Height of “'+cellStyleName+'”');
function sizeRows ()
{
cellarray = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();
for (a=0; a<cellarray.length; a++)
if (cellarray[a].appliedCellStyle.name == cellStyleName)
cellarray[a].height = newHeight;
} -
August 28, 2010 at 5:14 am #52831
Theunis De Jong
MemberThis is super-fancy if you need several variants. Save this script as “Resize_Cell Style Name_New Size.jsx”, and it'll pick up the variables from the script name :) (For instance, “Resize_Yellow Cells_10mm.jsx”.)
if (app.activeScript.name.match(/_/g).length == 2)
{
cellStyleName = app.activeScript.name.split('_')[1];
newHeight = app.activeScript.name.split('_')[2].split('.')[0];
if (app.activeDocument.cellStyles.item(cellStyleName).isValid)
app.doScript (sizeRows, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, “Undo Resize Height of “+cellStyleName);
else
alert ('There is no Cell Style named “'+cellStyleName+'”');
} else
alert ('The name “'+app.activeScript.name+'” should be in the format “Resize_CellStyleName_Height.jsx”!');
function sizeRows ()
{
cellarray = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();
for (a=0; a<cellarray.length; a++)
if (cellarray[a].appliedCellStyle.name == cellStyleName)
cellarray[a].height = newHeight;
} -
August 28, 2010 at 5:17 am #52832
avanti
ParticipantYou're killing me after all those hours of research !
It's just… OK and seems much faster than the first script.Thanks for all and the elevator muzak while waiting about… 30 seconds (reminded me the “Blues brothers”, at the end of the movie, except it was longer for them !).
No thanks to Adobe that doesn't seem to care about height / width of styled cells.
Have a nice week-end !
-
August 28, 2010 at 5:20 am #52833
Theunis De Jong
MemberA small addendum: the Name_Script stuff does not play nice with decimal points in your value. Change line #4 to this to solve it:
newHeight = app.activeScript.name.split('_')[2].split('.jsx')[0];
-
August 28, 2010 at 8:18 am #52834
avanti
ParticipantSuper fancy… it's too much !
Why not a script with user interface to choose cell styles in a drop down menu… (i'll think about it after all, we could make money ;-).It seems there's a little problem with the condition (line 5) :
if (app.activeDocument.cellStyles.item(cellStyleName).isValid)Message from INDD :
There is no Cell Style named “myCellStyle”It's OK when // (commentary mark in english ?) the “if” and “else” (lines 7 and 8).
When it'll be done, i'll post the multiple scripts you've made in an archive for other people and send it on Adobe forums too where i asked for help.
-
August 28, 2010 at 8:57 am #52835
Theunis De Jong
Member.. but but but .. I added the message there to warn there is no Cell Style named “myCellStyle” in your document!
You are supposed to use the correct cell style name in the script name. If you name the script “Resize_SomeTotallyRandomNameHere_5mm.jsx”, it'll try to use “SomeTotallyRandomNameHere” for a Cell Style name — and if you don't have that style, it'll warn you and don't do anything at all.
-
August 28, 2010 at 6:10 pm #52836
avanti
ParticipantI understood this Jongware but i have a style call “myCellStyle” in the document for using with previous versions of the script ;-)
-
August 28, 2010 at 11:28 pm #52837
David BlatnerKeymasterThis is great information, but it would be terrific if you continued it in the Scripting section of the forums. (I think most users don't really want to look at all that code!) :)
-
August 29, 2010 at 7:37 am #52838
avanti
ParticipantSure David but Jongware JS code is a valuable answer to the missing Adobe's function in cells style.
What about moving this topic to the Scripting section so we could continue the discussion with the first part?
Could do this as an administrator, please?To Jongware
I tried the fancy script with another document cell style (“ChangeStyledCellsHeight-v1.3_Heure_12mm.jsx”) and the alert shows again : There is no Cell Style named “Heure”
I tried to simplify the script name (“script_Heure_12mm.jsx”) with no more success.
I think the condition “if (app.activeDocument.cellStyles.item(cellStyleName).isValid)” is not true.
So why the cell style name is detected as not valid?Could it be a problem with french version of CS5 or CS5 itself or… (so many questions)?
-
October 9, 2012 at 10:28 pm #52839
Al
MemberHi,
I need your help with this script you been working around. I can find it very useful and I tried to apply and works good but there is a tiny problem that I don't knowhow to fix yet as I am just strating to dive a bit into this fascinating world of scripting.
If I apply this script
app.activeDocument.stories.everyItem().tables.everyItem().columns[0].width = “8mm”;
app.activeDocument.stories.everyItem().tables.everyItem().columns[1].width = “36mm”;It clearly picks up every item (every table) from my story. But what if I want just to select tables made of two colums or just selected ones instead to apply the script?
How can I tell those conditions?
Thank you very much
Al
-
-
AuthorPosts
- The forum ‘General InDesign Topics (CLOSED)’ is closed to new topics and replies.
