🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #20438

Re: Photobook script or plugin?

#20438
From: Olav Kvern
Date: Wed, 10 Jul 2002 19:07
108 lines
5896 bytes
Chris-- 

Here's a script that will do what you want. This script works in OS 10.1.5, and might need to be tweaked a bit to work with older system/AppleScript versions. It's not *read only*, so you can learn from it and change it to suit your needs--I can't understand why anyone would distribute a *script* as read only. 

--PlaceAllFilesWithFileName 
--This script attempts to place all files found in a specified folder and adds a label 
--to each frame containing the full file path to the file. 
--If you don't want to remove empty frames, set myRemoveEmptyFrames to false. 
set myRemoveEmptyFrames to true 
--Set up the page layout by entering the number of rows and columns you want. 
set myNumberOfRows to 3 
set myNumberOfColumns to 4 
--myOffset defines the height of the text frame for the labels. 
set myOffset to 24 
set myFramesPerPage to (myNumberOfRows * myNumberOfColumns) 
--Display a "Choose Folder" dialog box. 
set myFolder to choose folder with prompt "Select the folder containing the files you want to place." 
tell application "Finder" 
	set myNumberOfFrames to (count files in folder myFolder) 
	set myFiles to files of myFolder 
	--The following line used to work in Mac OS 9.x, but doesn't seem to in OS 10.1.5/AppleScript 1.8.3 
	--set myFiles to sort files of myFolder by name 
end tell 
tell application "InDesign 2.0.1" 
	set myDocument to make document 
	--Set the measurement units to points if they're not already set to points. 
	set myViewPreferences to view preferences of myDocument 
	if horizontal measurement units of myViewPreferences is not points then 
		set myOldXUnits to horizontal measurement units of myViewPreferences 
		set myResetXUnits to true 
		set horizontal measurement units of myViewPreferences to points 
	else 
		set myResetXUnits to false 
	end if 
	if vertical measurement units of myViewPreferences is not points then 
		set myOldYUnits to horizontal measurement units of myViewPreferences 
		set myResetYUnits to true 
		set vertical measurement units of myViewPreferences to points 
	else 
		set myResetYUnits to false 
	end if 
	--Create a paragraph style for the label 
	set myParagraphStyle to make paragraph style with properties {name:"label", point size:6} 
	set myDocumentPreferences to document preferences of myDocument 
	set myNumberOfPages to round (myNumberOfFrames / myFramesPerPage) rounding up 
	set pages per spread of myDocumentPreferences to 1 
	set pages per document of myDocumentPreferences to myNumberOfPages 
	set myMarginPreferences to margin preferences of page 1 of myDocument 
	set myLeftMargin to margin left of myMarginPreferences 
	set myRightMargin to margin right of myMarginPreferences 
	set myTopMargin to margin top of myMarginPreferences 
	set myBottomMargin to margin bottom of myMarginPreferences 
	set myLiveWidth to (page width of myDocumentPreferences) - (myLeftMargin + myRightMargin) 
	set myLiveHeight to (page height of myDocumentPreferences) - (myTopMargin + myBottomMargin) 
	set myFrameWidth to (myLiveWidth / myNumberOfColumns) 
	set myFrameHeight to (myLiveHeight / myNumberOfRows) 
	set myPages to pages of myDocument 
	repeat with myCounter from (count myPages) to 1 by -1 
		set myPage to item myCounter of myPages 
		repeat with myRowCounter from myNumberOfRows to 1 by -1 
			set myY1 to myTopMargin + (myFrameHeight * (myRowCounter - 1)) 
			set myY2 to myTopMargin + (myFrameHeight * myRowCounter) 
			repeat with myColumnCounter from myNumberOfColumns to 1 by -1 
				set myX1 to myLeftMargin + (myFrameWidth * (myColumnCounter - 1)) 
				set myX2 to myLeftMargin + (myFrameWidth * myColumnCounter) 
				tell myPage to make rectangle with properties {geometric bounds:{myY1, myX1, myY2, myX2}} 
				tell myPage to make text frame with properties {geometric bounds:{myY2 - myOffset, myX1, myY2, myX2}} 
			end repeat 
		end repeat 
	end repeat 
	repeat with myCounter from 1 to myNumberOfFrames 
		set myFileName to item myCounter of myFiles as string 
		set myRectangle to rectangle myCounter of myDocument 
		tell myRectangle 
			place myFileName 
		end tell 
		--Position/fit the graphic in the frame. 
		fit myRectangle given content to frame 
		fit myRectangle given proportionally 
		fit myRectangle given center content 
		--Add the file name to the text frame. 
		tell text frame myCounter of myDocument 
			set contents to (myFileName as string) 
			set applied paragraph style of paragraph 1 to paragraph style "label" of myDocument 
		end tell 
	end repeat 
	--Do cleanup, if necessary. 
	if myRemoveEmptyFrames is true then 
		tell myDocument 
			tell (every rectangle whose content type is unassigned) to delete 
			tell (every text frame whose contents is "") to delete 
		end tell 
	end if 
	--Reset the measurement units, if necessary. 
	if myResetXUnits is true then 
		set horizontal measurement units of myViewPreferences to myOldXUnits 
	end if 
	if myResetYUnits is true then 
		set vertical measurement units of myViewPreferences to myOldYUnits 
	end if 
end tell 
 

Hope this helps! 

Thanks, 

Ole
Technical Details
Message-ID: <ef98d69.1@WebX.aaQKaf7vad4>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-08!supernews.com!newsswitch.lcs.mit.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX
References: <ef98d69.-1@WebX.aaQKaf7vad4>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f939a,9d17966dab9a2c44
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2002-07-10 13:34:48 PST
From: "Olav Kvern" <okvern@adobe.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-08!supernews.com!newsswitch.lcs.mit.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX
Newsgroups: adobe.scripting.indesign
Subject: Re: Photobook script or plugin?
Message-ID: <ef98d69.1@WebX.aaQKaf7vad4>
Date: Wed, 10 Jul 2002 12:07:03 -0700
References: <ef98d69.-1@WebX.aaQKaf7vad4>
Lines: 126
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit