Make tables and format

(See below for my edits and updates. I didn’t want to reply to my own posts…)


I’m new here, not new to applescript. I have worked with Quark XPress and applescript with good result some years ago but would like to start scripting Indesign.

I have the following:

I have a text which I can ‘find GREP’
I do however not want to do a ‘change GREP’ but I’d like to make a table with the found text and give it a certain width Height and stroke.

I know the convert to table method but I don’t know how to do this on the GREP I found.
I also don’t know how to set the width and Height of a table.

Any suggestions welcome and thanks in advance!
Oh, and I’d like to buy a good book. Any suggestions??

I did manage to make a script to ‘do something’ with every table.
Now I have to find how to format the tables.
For some reason the “TableFormatting.applescript” as provided in the “indesign_cs5_scripting_guide_scripts” doesn’t work at all. It simply doesn’t want to format the tables it makes itself.

Here is the script I came up with to ‘do something’ to every table.
It is is perhaps not the best script but it works for now…

tell application "Adobe InDesign CS4"
	if (count documents) > 0 then
		if (count stories of active document) > 0 then
			my myDisplayDialog()
			display dialog "The active document contains no text. Please open a document containing text and try again."
		end if
		display dialog "No documents are open. Please open a document and try again."
	end if
end tell

on myDisplayDialog()
end myDisplayDialog
tell application "Adobe InDesign CS4"
	set myDocument to active document
	repeat with myCounter from 1 to (count stories of myDocument)
		set myStory to story myCounter of myDocument
		tell every table of myStory
			--here is where the formatting should take place
                        --do something ;)
		end tell
	end repeat
end tell

Ok, I’m confused now. Why doesn’t it even do: “set row type of row 1 to header row” when I put that in the '–do something" part of this script… in fact why doesn’t it work in the samplescripts provided by Adobe. Help!
I know I must be pointing at the tables in my document because when I say ‘delete’ is does delete all my tables. Meh, not something I want to do :wink:

Model: minimac
AppleScript: 2.1.2
Browser: Firefox 3.6.3
Operating System: Mac OS X (10.6)

Okay, now replying to myself to keep things clear… :rolleyes:

I finaly came up with a way to do a GREP find and change that into a table.
You will need a document with fractions for this specific script to work, by changing the row and column separators you can use different formats.
If you’d like to try it, make a new document and type some fractions and run this script.

What it does is do a find grep and a change grep but instead of cleaning up the find/change grep with: ‘set find grep preferences to nothing’ and ‘set change grep preferences to nothing’ I make a loop with the list of ‘find grep’.
Then in reverse order make tables of every item in this list. It has to be reverse order because as the loop runs it changes the order of the text and thus changing the places where the fractions where. I hope this is clear.
The only problem now is that i want the tables to flow in the text like the fractions did so I have to find a way to pull them out of the text and place them in a text frame and place the text frame back where the table came from.

Here is the script:

--find/change grep preferences
tell application "Adobe InDesign CS4"
	set myDocument to document 1
	set find grep preferences to nothing
	set change grep preferences to nothing
	--Set the find options.
	set include footnotes of find change grep options to false
	set include hidden layers of find change grep options to false
	set include locked layers for find of find change grep options to false
	set include locked stories for find of find change grep options to false
	set include master pages of find change grep options to false
	set find what of find grep preferences to "(\\d+/\\d+)"
	--to change the point size of the found items
	set point size of change grep preferences to 6.5
	change grep
	--to make tables of the found items
	tell myDocument
		set searchResults to find grep "(\\d+/\\d+)"
		repeat with i from (count of searchResults) to 1 by -1 -- reverse order
			tell item i of searchResults
				convert to table column separator "-" row separator "/"
				set myTable to result
				--insert table properties here
			end tell
		end repeat
	end tell
	--Clear the find/change preferences after the search.
	set find grep preferences to nothing
	set change grep preferences to nothing
	end tell