This section represents the beginnings of a solution to create business cards from example files using InDesign.

  1. Properties: Object Properties
  2. Creation: Get Structure InD
  3. Creation: Build Cards InD

return

Properties

InD

Here is a sample of the properties of a page item. It is a structured list. You can address, for example the geometric bounds of the text frame directly. Note how many of the items contain references to other things: stroke color:swatch id 14 of document "wsitsnmcrp.indd"the swatch color being defined elsewhere in the document (and is only available to that document, so you will have to define it in any new documents you create)


--running this script when a document containing at least one text frame is open
tell application "Adobe InDesign CS2"
 tell document 1
  set myList to all page items of page 1
  set myProps to properties of item 2 of myList
 end tell
end tell
--gives for example the following list of the properties of one of the page items
(*
get properties of text frame id 323 of page id 160 of spread id 155 of document "wsitsnmcrp.indd"

{absolute rotation angle:0.0, absolute horizontal scale:100.0, absolute shear angle:0.0, absolute vertical scale:100.0, baseline frame grid options:baseline frame grid options of text frame id 323 of page id 160 of spread id 155 of document "wsitsnmcrp.indd", id:323, overflows:false, overridden:false, associated XML element:nothing, all graphics:{}, all page items:{}, applied object style:object style id 110 of document "wsitsnmcrp.indd", content type:text type, end cap:butt end cap, end join:miter end join, fill tint:-1.0, fill color:swatch id 14 of document "wsitsnmcrp.indd", start text frame:text frame id 323 of page id 160 of spread id 155 of document "wsitsnmcrp.indd", gap color:swatch id 14 of document "wsitsnmcrp.indd", gap tint:-1.0, geometric bounds:{61.504, 151.4975, 134.296, 242.7215}, text frame index:1, rotation angle:0.0, stroke tint:-1.0, left line end:none, stroke color:swatch id 14 of document "wsitsnmcrp.indd", stroke weight:0.0, end text frame:text frame id 323 of page id 160 of spread id 155 of document "wsitsnmcrp.indd", miter limit:4.0, nonprinting:false, next text frame:nothing, overridden master page item:nothing, anchored object settings:anchored object settings of text frame id 323 of page id 160 of spread id 155 of document "wsitsnmcrp.indd", local display setting:default, shear angle:0.0, text frame preferences:text frame preferences of text frame id 323 of page id 160 of spread id 155 of document "wsitsnmcrp.indd", parent:page id 160 of spread id 155 of document "wsitsnmcrp.indd", corner effect:none, contents:"555 El KitchenCinco Avenue, Suite 500
Irving, California 92555
Toll Free 800-555-1234
Phone 949-555-0550 ext. 555
Fax 949-555-0551", corner radius:0.0, gradient fill angle:0.0, gradient fill length:0.0, gradient stroke angle:0.0, gradient stroke length:0.0, gradient stroke start:{197.1095, 97.9}, gradient fill start:{197.1095, 97.9}, horizontal scale:100.0, index:2, item layer:layer id 152 of document "wsitsnmcrp.indd", locked:false, object reference:text frame id 323 of page id 160 of spread id 155 of document "wsitsnmcrp.indd", label:"", previous text frame:nothing, vertical scale:100.0, right line end:none, stroke alignment:center alignment, parent story:text flow id 427 of document "wsitsnmcrp.indd", stroke type:stroke style id 23081 of document "wsitsnmcrp.indd", text wrap preferences:text wrap preferences of text frame id 323 of page id 160 of spread id 155 of document "wsitsnmcrp.indd", visible bounds:{61.504, 151.4975, 134.296, 242.7215}, isolate blending:false, knockout group:false, blend mode:normal, opacity:100.0, shadow blend mode:multiply, shadow color:color id 11 of document "wsitsnmcrp.indd", shadow mode:none, shadow noise:0.0, shadow opacity:75.0, shadow blur radius:5.0, shadow spread:0.0, shadow x offset:7.0, shadow y offset:7.0, feather corner type:diffusion, feather mode:none, feather noise:0.0, feather width:9.0}
end tell
*)

--We could also address parts of the properties directly
  set myBounds to geometric bounds of item 2 of document 1 of myList


return

Get Structure

InD

This script takes the three file names in the parameters field (they need to be on the desktop), opens them and puts their data into the business card tables. It then opens the business card tables We had to set the tell to the appropriate version of FMP (Pro or Advanced)


--set up globals so they can be used anywhere in the script
--without having to think about them again
global myItemList
global myList
global tempFile
global myResult
global myRecord
global dsktp
global tempDocRef
tell application "FileMaker Pro"
 tell current record
  set myRecord to ID as integer
  set myResult to cell "parameters"
  tell (a reference to my text item delimiters) --Later in the script we use exactly the same code as a a sub-routine (deListMe)
   set {oldDelim, contents} to {contents, return}
   set {myResult, contents} to {(text items 1 through 3 of myResult) as list, oldDelim}
  end tell
 end tell
end tell
tell application "Finder"
 activate
 set dsktp to desktop as text
 repeat with thisResult in myResult
  try --Here's some error trapping. For if the file isn't where we expect it
   open alias (dsktp & thisResult)
   my getCard()
  on error
   try
    display dialog "The file '" & thisResult & "' is not on the desktop!"
   on error --User can cancel or continue. Cancel is of course a species of error
    tell me
     activate
    end tell
    return
   end try
  end try
 end repeat
end tell
tell application "FileMaker Pro"
 tell current record
  do script "openCardWindows"
 end tell
end tell

on getCard()
 set myItemList to {}
 set tempFile to "New"
 tell application "Adobe InDesign CS2"
  tell document 1
   set myList to all page items of page 1
   set i to 1
   repeat with thisItem in myList
    tell thisItem
     --this section collects the data into a list for later use by the script itself 
     copy {(class as text)} to end of myItemList
     copy geometric bounds to end of last item of myItemList
     if (class as text) is "text frame" then
      copy (contents of properties) to end of last item of myItemList
      copy (vertical justification of text frame preferences) to end of last item of myItemList
      copy (name of applied font of every paragraph) to end of last item of myItemList --or font family
      copy (point size of every paragraph) to end of last item of myItemList
      copy (name of fill color of every paragraph) to end of last item of myItemList
      copy (leading of every paragraph) to end of last item of myItemList
      copy (justification of every paragraph) to end of last item of myItemList
      copy (tracking of every paragraph) to end of last item of myItemList
      copy (horizontal scale of every paragraph) to end of last item of myItemList
      copy (font style name of applied font of every paragraph) to end of last item of myItemList
     end if
     --Although in reality  
     if (exists graphics) then
      copy (class of graphic 1 as text) to end of last item of myItemList
      copy (file path of item link of graphic 1) to end of last item of myItemList
      copy (absolute horizontal scale of all graphics) to end of last item of myItemList
      copy (absolute vertical scale of all graphics) to end of last item of myItemList
     end if
     --and this section collects it as text (just as an example: we're not using it)
     if (class as text) is "text frame" then
      set myBounds to geometric bounds
      set myColours to (name of fill color of every paragraph)
      tell (a reference to my text item delimiters)
       set {oldDelim, contents} to {contents, " "}
       set {myColours, myBounds, contents} to {"" & myColours, "" & myBounds, oldDelim}
      end tell
      set myResult to (class as text) & return & myBounds
      set myResult to myResult & return & (vertical justification of text frame preferences) & 
       return & myColours & return & (contents of properties) as text
     end if
     if (exists graphics) then
      set myResult to (class as text) & return & myBounds
      set myResult to myResult & return & (class of graphic 1 as text) & return & (file path of item link of graphic 1) & 
       return & (absolute horizontal scale of all graphics) & " " & (absolute vertical scale of all graphics)
     end if
     --and this one  puts the first section's data into FileMaker
     -- This needs to be changed to ' tell application "FileMaker Pro" ' if you are running from Pro 
     tell application "FileMaker Pro"
      activate
      go to layout "cardStructure"
      set tempDocRef to ""
      try
       go to last record
       if tempFile is "New" then
        set tempFile to ((cell "cardTypeNumber" of current record) as integer) + 1
        tell application "Adobe InDesign CS2"
         set view PDF of PDF export preferences to false
         set tempDocRef to (dsktp & tempFile & ".pdf")
         export document 1 format PDF type to tempDocRef
        end tell
       else
        set tempDocRef to ""
       end if
      on error
       set tempFile to 1
       tell application "Adobe InDesign CS2"
        set view PDF of PDF export preferences to false
        set tempDocRef to (dsktp & tempFile & ".pdf")
        export document 1 format PDF type to tempDocRef
       end tell
      end try
      if tempDocRef is not "" then
       go to layout "card"
       set thisCardRecord to create new record at end
       tell thisCardRecord
        set cell "cardTypeNumber" to tempFile
        set cell "cardPDF" to (alias tempDocRef) --this inserts a reference: 
        --if you want to insert the actual image you'll need to do script in FileMaker that inserts the picture
        set cell "fixedText1" to "WhatsitsName Corporation" & return & "A Subsidiary of SomeOtherBloodyBigCorp"
       end tell
       go to layout "cardStructure"
      end if
      set thisRecord to create new record at end
      tell thisRecord
       set cell "cardTypeNumber" to tempFile
       set cell "cardItemNumber" to i
       set cell "class" to (item 1 of last item of myItemList) as text
       --the geometric bounds are often given to ridiculous precision: 
       --    1/72000 of an inch should be QUITE enough
       --    so these call a rounding handler (see the bottom of this Script)
       --    note the use of 'my'.
       set cell "bounds" to {my roundMe(item 1 of item 2 of last item of myItemList, 3), my roundMe(item 2 of item 2 of last item of myItemList, 3), my roundMe(item 3 of item 2 of last item of myItemList, 3), my roundMe(item 4 of item 2 of last item of myItemList, 3)}
       if item 1 of last item of myItemList is "text frame" then
        set cell "itemID" to (text items 1 thru 7 of item 3 of last item of myItemList) as text
        set cell "vertAlign" to (item 4 of last item of myItemList) as text
        --the deListMe handler handles turning lists into text with returns 
        --    (so fmp can treat them as values)
        set cell "font" to my deListMe(item 5 of last item of myItemList, return)
        set cell "typeSize" to my deListMe(item 6 of last item of myItemList, return)
        set cell "typeColour" to my deListMe(item 7 of last item of myItemList, return)
        set cell "leading" to my deListMe(item 8 of last item of myItemList, return)
        set cell "justification" to my deListMe(item 9 of last item of myItemList, return)
        set cell "tracking" to my deListMe(item 10 of last item of myItemList, return)
        set cell "scaleHorizontal" to my deListMe(item 11 of last item of myItemList, return)
        set cell "fontStyle" to my deListMe(item 12 of last item of myItemList, return)
       end if
       if item 3 of last item of myItemList is "PostScript picture" then
        set cell "graphicClass" to (item 3 of last item of myItemList) as text
        set cell "filePath" to (item 4 of last item of myItemList) as text
        set cell "absHorizScale" to my roundMe(item 5 of last item of myItemList, 3)
        set cell "absVertScale" to my roundMe(item 5 of last item of myItemList, 3)
       end if
       set i to i + 1
      end tell
     end tell
    end tell
   end repeat
  end tell
  close document 1
 end tell
end getCard

on deListMe(mydeList, newSep)
 tell (a reference to my text item delimiters)
  set {oldDelim, contents} to {contents, newSep}
  set {mydeList, contents} to {"" & mydeList, oldDelim}
  return mydeList
 end tell
end deListMe

on roundMe(myNum, myPlaces)
 set myNum to (round (myNum * (10 ^ myPlaces)) rounding as taught in school) / (10 ^ myPlaces)
 return myNum
end roundMe


return

Build Cards

InD

This script is run outside FileMaker once it has been saved from Script Editor as an application (in the workshop we added an activate just after the tell InD so we could watch it run. We also had to set the tell to the appropriate version of FMP (Pro or Advanced) It parses the Business Card data and creates 1 or more instances (depending on quantities required) stepping and repeating through the InDesign document it creates, adding pages as necessary.


tell application "Finder"
 set dsktp to desktop as text -- get the desktop of the computer we're running on (which is where we have saved the application). 
 open alias (dsktp & "docMaker.app")
end tell

InD

And this is the script


global myItemList
global tempFile
property pageHeight : 440
property pageWidth : 760
property horizontalStep : 251.928
property verticalStep : 144.035
--for type fitting routine
property deltatr : 4
property deltahs : 4
property breakpoint : -80
property limitpoint : -100
-- end for type fitting routine

set myItemList to {}
tell application "Adobe InDesign CS2"
	set oldTextDefaults to point size of text defaults --so we can reset when finished
	tell text defaults --so that text is small enough to fit in boxes
		set point size to 4
	end tell
	set myViewPreferences to view preferences
	tell myViewPreferences
		set horizontal measurement units to points
		set vertical measurement units to points
	end tell
	set myDocPrefs to document preferences
	tell myDocPrefs
		set {pages per document, page orientation, page height, page width} to {1, portrait, pageHeight, pageWidth}
	end tell
	set myMarginPrefs to margin preferences
	tell myMarginPrefs
		set top to 0
		set bottom to 0
		set left to 0
		set right to 0
	end tell
	set tempdoc to make new document
	zoom layout window 1 given fit page
	tell tempdoc
		if not (exists swatch "C=15 M=100 Y=100 K=0" of tempdoc) then --if its already there itll give an error
			make new color with properties {model:spot, color value:{15.0, 100.0, 100.0, 0.0}, space:CMYK, name:"C=15 M=100 Y=100 K=0"}
		end if
		if not (exists swatch "C=100 M=90 Y=10 K=0" of tempdoc) then
			make new color with properties {model:spot, color value:{100.0, 90.0, 10.0, 0.0}, space:CMYK, name:"C=100 M=90 Y=10 K=0"}
		end if
		set tempwindow to layout window 1
		set transform reference point of tempwindow to top left anchor
		set zero point to {0, 0}
		set currentVertStep to verticalStep
		set currentHorizStep to horizontalStep
		repeat while (currentVertStep + verticalStep) < pageHeight
			make new guide with properties {orientation:horizontal, location:currentVertStep}
			
			set currentVertStep to currentVertStep + verticalStep
		end repeat
		repeat while (currentHorizStep + horizontalStep) < pageWidth
			make new guide with properties {orientation:vertical, location:currentHorizStep}
			set currentHorizStep to currentHorizStep + horizontalStep
		end repeat
		set currentVertStep to 0
		set currentHorizStep to 0
	end tell
 -- This needs to be changed to ' tell application "FileMaker Pro" ' if you are running from Pro 
	tell application "FileMaker Pro Advanced"
		tell window 1
			set multi to false
			set i to 1
			set z to (count of (every record of current layout))
			tell application "Adobe InDesign CS2"
				tell document 1
					set thisPage to page 1
					repeat while i  z
						repeat while (currentVertStep + verticalStep) < pageHeight
							repeat while (currentHorizStep + horizontalStep) < pageWidth
								set zero point to {currentHorizStep, currentVertStep}
								--do step
								set myDataCount to 1
								tell thisPage
									tell application "FileMaker Pro Advanced"
										go to layout "data"
										try
											go to record i
										on error
											return
										end try
										set k to cell "cardTypeNumber" of current record as integer
										if not multi then set j to cell "quantity" of current record as integer
										if j > 1 then
											set multi to true
										else
											set multi to false
										end if
										go to layout ("dataForType" & k & "Script")
										set myData to current record
										do script "getStructure"
										set myItemList to every record of current layout
										repeat with thisSubList in myItemList
											repeat with l from 4 to 11
												set item l of thisSubList to my listMe(item l of thisSubList, return)
											end repeat
										end repeat
									end tell
									repeat with thisItem in myItemList
										if item 1 of thisItem is "text frame" then
											set thisUn to make text frame at end with properties {geometric bounds:item 2 of thisItem, contents:item myDataCount of myData}
											if (item 3 of thisItem) is "bottom align" then set (item 3 of thisItem) to bottom align
											if (item 3 of thisItem) is "center align" then set (item 3 of thisItem) to center align
											if (item 3 of thisItem) is "top align" then set (item 3 of thisItem) to top align
											if (item 3 of thisItem) is "justify align" then set (item 3 of thisItem) to justify align
											set (vertical justification of text frame preferences) of thisUn to (item 3 of thisItem)
											set m to 1
											repeat with thisPara in every paragraph of thisUn
												if ((item m of item 9 of thisItem) is "left align" or (item m of item 9 of thisItem) is "left") 
													then set (item m of item 9 of thisItem) to left align
												if ((item m of item 9 of thisItem) is "center align" or (item m of item 9 of thisItem) is "center") 
													then set (item m of item 9 of thisItem) to center align
												if ((item m of item 9 of thisItem) is "right align" or (item m of item 9 of thisItem) is "right") 
													then set (item m of item 9 of thisItem) to right align
												if (item m of item 9 of thisItem) is "left justified" then set (item m of item 9 of thisItem) to left justified
												if (item m of item 9 of thisItem) is "right justified" then set (item m of item 9 of thisItem) to right justified
												if (item m of item 9 of thisItem) is "center justified" then set (item m of item 9 of thisItem) to center justified
												if (item m of item 9 of thisItem) is "fully justified" then set (item m of item 9 of thisItem) to fully justified
												if (item m of item 9 of thisItem) is "to binding side" then set (item m of item 9 of thisItem) to to binding side
												if (item m of item 9 of thisItem) is "away from binding side" then set (item m of item 9 of thisItem) to away from binding side
												set applied font of paragraph m of thisUn to item m of item 4 of thisItem
												set point size of paragraph m of thisUn to item m of item 5 of thisItem
												set fill color of paragraph m of thisUn to item m of item 7 of thisItem
												if (item m of item 8 of thisItem) is "auto" then set (item m of item 8 of thisItem) to auto
												set leading of paragraph m of thisUn to item m of item 8 of thisItem
												set justification of paragraph m of thisUn to item m of item 9 of thisItem
												set tracking of paragraph m of thisUn to (item m of item 10 of thisItem) as real
												set horizontal scale of paragraph m of thisUn to (item m of item 11 of thisItem) as real
												set m to m + 1
											end repeat
											my typeFit(contents of thisUn)
										end if
										if item 1 of thisItem is "rectangle" then
											set thisUn to make rectangle at end with properties {geometric bounds:item 2 of thisItem, fill color:"None", stroke weight:0}
											set myPic to place (item 13 of thisItem) as alias on thisUn with properties {absolute horizontal scale:(item 14 of thisItem) as real, absolute vertical scale:(item 15 of thisItem) as real}
										end if
										set myDataCount to myDataCount + 1
									end repeat
									if j > 1 then
										set j to j - 1
									else
										set i to i + 1
									end if
								end tell
								set currentHorizStep to currentHorizStep + horizontalStep
							end repeat
							set currentHorizStep to 0
							set currentVertStep to currentVertStep + verticalStep
						end repeat
						set zero point to {0, 0}
						set thisPage to make new page at end
						tell thisPage
							set currentVertStep to verticalStep
							set currentHorizStep to horizontalStep
							repeat while (currentVertStep + verticalStep) < pageHeight
								make new guide with properties {orientation:horizontal, location:currentVertStep}
								set currentVertStep to currentVertStep + verticalStep
							end repeat
							repeat while (currentHorizStep + horizontalStep) < pageWidth
								make new guide with properties {orientation:vertical, location:currentHorizStep}
								set currentHorizStep to currentHorizStep + horizontalStep
							end repeat
							set currentVertStep to 0
							set currentHorizStep to 0
						end tell
						set currentHorizStep to 0
						set currentVertStep to 0
					end repeat
				end tell
			end tell
		end tell
	end tell
	set point size of text defaults to oldTextDefaults
end tell

on listMe(textForList, newSep)
	tell (a reference to my text item delimiters)
		set {oldDelim, contents} to {contents, newSep}
		set {textForList, contents} to {(every text item of textForList) as list, oldDelim}
		return textForList
	end tell
end listMe

on typeFit(myText)
	tell application "Adobe InDesign CS2"
		tell myText
			set countOPara to count of paragraphs
			set k to 1
			repeat while k  countOPara
				if exists line 2 of paragraph k then
					repeat while exists line 2 of paragraph k
						set tr to tracking of paragraph k
						if tr < breakpoint then
							set hs to horizontal scale of paragraph k
							if tr > limitpoint then
								set tracking of paragraph k to tr - deltatr
							end if
							set horizontal scale of paragraph k to hs - deltahs
						else
							set tracking of paragraph k to tr - deltatr
						end if
					end repeat
				end if
				set k to k + 1
			end repeat
		end tell
	end tell
end typeFit



return