I’m trying my hand at creating tables and having a hard go of it. Can someone share a script that creates tables with properties, or a script that creates a table and shows me how to get the properties of that table? Also I’d appreciate any help getting data into specific cells.
This is from an ASS app. that I am currently working on. Some of the variables used have been set up previously. This table is created on the first master spread of the document. The first handler creates the table, sets the stroke weight and fills each cell with a color defined during a different part of the script.
The second handler fills each cell of the table with data that has been gathered previously.
to CreateSlug()
tell application "InDesign CS"
tell theDocument
set the horizontal measurement units of view preferences to picas
set the vertical measurement units of view preferences to picas
set the slug top offset of document preferences to 4.5
set the pWidth to the page width of document preferences
set theMPage to the first master spread
set theTFrame to make new text frame at theMPage with properties {visible bounds:{-4.5, 0, -0.25, pWidth}}
set theTable to make new table at theTFrame with properties {width:51, column count:6, body row count:3, left border stroke weight:0.0208333, right border stroke weight:0.0208333, top border stroke weight:0.0208333, bottom border stroke weight:0.0208333, label:"CIP Slug"}
tell theTable
merge cell id 0 with cell id 1
repeat with x from 1 to 17
tell cell x
set the width to (item x of theWidths)
set the minimum height to 1.25
set the left edge stroke weight to 0.0208333
set the right edge stroke weight to 0.0208333
set the top edge stroke weight to 0.0208333
set the bottom edge stroke weight to 0.0208333
set the fill color to swatch (item x of theFillColors) of theDocument
end tell
end repeat
end tell
end tell
end tell
return pWidth
end CreateSlug
to PopulateSlug()
tell application "InDesign CS"
repeat with x from 1 to 17
set the contents of cell x of theTable to item x of theContents
set the point size of the text of cell x of theTable to 6
set the applied font of the text of cell x of theTable to "Helvetica"
set the font style of the text of cell x of theTable to "Medium"
set the fill color of the text of cell x of theTable to swatch (item x of theTextColors) of theDocument
end repeat
end tell
end PopulateSlug
Any idea of how to get a graphic inserted into a cell? I’ve tried all the permutations of place I can think of with only a “blah, blah, blah doesn’t understand the place command”, or an access not allowed message.
since the contents of a cell is text then you need to place an inline rectangle in the cell and the image in that
set placedimage to (choose file) as string
tell application "InDesign CS"
tell document 1
tell table 1 of story 1
tell cell 1
set NewImage to make new rectangle at insertion point 1 with properties {label:"Photo 1"}
set ImageBounds to geometric bounds of NewImage
set geometric bounds of NewImage to {item 1 of ImageBounds, item 2 of ImageBounds, (item 1 of ImageBounds) + 24, (item 2 of ImageBounds) + 18}
end tell
end tell
set x to object reference of NewImage
place placedimage on NewImage
end tell
end tell
Hm. I was missing the insertion point part.
Heyzues. Did you take a class on this? How do you people keep this stuff straight? I have to constantly go back to other scripts I’ve created to pick up/remind myself what I did to get things to work.
Thanks for explaining the why and how of this problem.
I played around a little more with my code, and it seems to intermitantly error out even when placing the same image. I’m not sure why this would be happening, same code, same ID file, same table, etc. I cleaned it up a little:
set placedimage to (choose file) as string
tell application "InDesign CS"
tell document 1
tell table 1 of story 1
tell cell 1
set NewImage to make new rectangle at insertion point 1 with properties {label:"Photo 1"}
set ImageBounds to geometric bounds of NewImage
set geometric bounds of NewImage to {item 1 of ImageBounds, item 2 of ImageBounds, (item 1 of ImageBounds) + 24, (item 2 of ImageBounds) + 18}
place placedimage on NewImage
end tell
end tell
end tell
end tell
Maybe someone else can see an error in my code. As to your other question, I’ve never taken a class for Applescript or Indesign, just played around with them. I keep a lot of code snippets to refer back to when I need to do something. Most of it is figuring out the object model that the programers use, and experience using their dictionary. Every program scripts a little different.
tell theTable
tell cell 10
set myColorBars to make new rectangle at insertion point 1 with properties {label:"ColorBars"}
set myPlacedColorBars to place "05_raid4:z_SAVE:New_QC_Steps.eps" on myColorBars
end tell
end tell