🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #8793

Re: images in folder to select graphic boxes

#8793
From: Carolyn_Finnell
Date: Tue, 26 Sep 2006 14:29
121 lines
6131 bytes
Here it is

(*
	Copyright � 1994-2003 - All Rights Reserved
	Quark, Inc. & Nyhthawk Productions
	 <http://www.Quark.com>
	 <http://members.aol.com/nyhthawk/welcome.html>

	Copying and sharing of this script in whole or in part is allowed. The authors are
	not responsible for any losses caused by the use of or failure of this software.
* )

tell application "QuarkXPress Passport"
	activate

	try
		-- This line will ensure that a document is open, before proceeding
		if not (exists document 1) then error "No document is open."

		-- This line will display an error if the current page is a master page
		if masterdoc of document 1 is true then error "This script doesn't work on master pages."

		tell current spread of document 1
			try
				-- This line will get the object of every selected picture box, and will error if no picture boxes are selected
				set foundPictBoxes to object reference of every picture box whose selected is true
			on error
				error "No picture boxes are selected."
			end try

			-- This line will ask the user to select the folder which contains the desired images
			set theFolder to choose folder with prompt "Pick a folder from which to auto-import the images."

			-- This line will allow the user to reverse the import order
			if length of foundPictBoxes > 1 then
				set importOrder to button returned of (display dialog "Do you want the images to begin importing into the topmost or bottommost picture box?" buttons {"Cancel", "Topmost", "Bottommost"} default button 3)
				-- For compatibility with non-US English operating systems
				if importOrder is "Bottommost" then
					set foundPictBoxes to reverse of foundPictBoxes
				else if importOrder is "Cancel" then
					error "User canceled." number -128
				end if
			end if

			-- This section will ask the user to specify if the images should be imported at 100% or if they should be auto fit to the box
			set fitOptions to {"Leave 100%", "Fit to Box", "Fit to Box (Proportionally)", "Fit Box to Picture", "Fit to Largest Percent"}
			set autoFitImages to (choose from list fitOptions with prompt "How should the images be scaled?" default items {"Fit to Box (Proportionally"})
			-- For compatibility with non-US English operating systems
			if autoFitImages is false then error "User canceled." number -128
			set autoFitImages to item 1 of autoFitImages

			try
				tell application "Finder"
					-- This section will make a list of the images that are in the specified folder
					set theImageList to every file of theFolder whose kind is not "alias" and �
						file type is "TIFF" or file type is "EPSF" or file type is "PICT" or �
						file type is "JPEG" or file type is "GIFf" or file type is "BMP " or �
						file type is "RIFF" or file type is "BINA" or file type is "PNTG" or �
						file type is "BMPf"

					-- This line will ensure that the class of the variable is a list. The following repeat is expecting a list
					if class of theImageList is not list then set theImageList to theImageList as list
				end tell
			on error
				error "No images were found in this folder."
			end try

			-- This section configures variables that will be used in the following repeat statement
			set theNumberOfImages to number of items of theImageList
			set theCounter to 1

			-- This repeat statement performs the bulk of the work
			repeat with i from 1 to (length of foundPictBoxes)
				-- This line imports the image, from the folder, into the picture box
				set image 1 of (item i of foundPictBoxes) to (item i of theImageList) as alias

				-- This section will automatically fit the image to the picture box, if specified by the user, to do so
				if autoFitImages is not "Leave 100%" then
					if autoFitImages is "Fit to Box" then
						set bounds of image 1 of item i of foundPictBoxes to exact fit
					else if autoFitImages is "Fit to Box (Proportionally)" then
						set bounds of image 1 of item i of foundPictBoxes to proportional fit
					else if autoFitImages is "Fit Box to Picture" then
						set bounds of image 1 of item i of foundPictBoxes to box fit
					else if autoFitImages is "Fit to Largest Percent" then
						try
							set bounds of image 1 of item i of foundPictBoxes to exact fit
							copy (scale of image 1 of item i of foundPictBoxes as list) to {imageHeight, imageWidth}
							copy {imageHeight as real, imageWidth as real} to {imageHeight, imageWidth}

							--AUTO FIT THE IMAGE TO THE PICTURE BOX
							if imageWidth > imageHeight then
								set newPercent to imageWidth
							else
								set newPercent to imageHeight
							end if
							set scale of image 1 of item i of foundPictBoxes to {newPercent, newPercent}
							set bounds of image 1 of item i of foundPictBoxes to centered
						on error errmsg number errnum
							error errmsg number errnum
						end try
					end if
				end if

				-- This if statement will exit the repeat statement, if there are no more images to import
				if i = theNumberOfImages then
					exit repeat
				end if
			end repeat
		end tell
		-- The following beep will provide feedback of script completion
		beep 2
	on error errmsg number errnum
		if errnum ? -128 then
			beep
			display dialog errmsg & " [" & errnum & "]" buttons {"OK"} default button 1 with icon stop
		end if
		-- For compatibility with non-US English operating systems
		return
	end try
end tell
Technical Details
Message-ID: <3bc1c6c5.1@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news3.google.com!news2.volia.net!news.musoftware.de!news.albasani.net!news.isoc.lu!webcrossing
References: <3bc1c6c5.-1@webcrossing.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,7abff512d9180145
X-Google-Attributes: gidf939a,public
X-Google-Language: ENGLISH,ASCII
From: Carolyn_Finnell@adobeforums.com
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news3.google.com!news2.volia.net!news.musoftware.de!news.albasani.net!news.isoc.lu!webcrossing
Newsgroups: adobe.scripting.indesign
Subject: Re: images in folder to select graphic boxes
Message-ID: <3bc1c6c5.1@webcrossing.la2eafNXanI>
Date: Tue, 26 Sep 2006 07:29:27 -0700
References: <3bc1c6c5.-1@webcrossing.la2eafNXanI>
Lines: 152
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit