Article View: adobe.scripting.indesign
Article #15045Re: Struggling with VBscript
From: Olav_Kvern
Date: Mon, 05 Jan 2004 22:59
Date: Mon, 05 Jan 2004 22:59
83 lines
4274 bytes
4274 bytes
Sharon--
You're not being a pain at all!
Here's an updated version of the earlier script (run this one from the InDesign Scripts palette):
Dim myInDesign
Rem Enter the number or rows and columns you want. If you're adding
Rem a user interface to this script, you can get these values from
Rem a pair of text fields.
myNumberOfRows = 4
myNumberOfColumns = 3
Rem If you want to remove any empty frames, set myRemoveEmptyFrames to true.
myRemoveEmptyFrames = True
Rem Enter the path to the folder containing the images you want to place.
myFolderName = "d:\myFilesToPlace"
myFramesPerPage = myNumberOfRows * myNumberOfColumns
Set myInDesign = CreateObject("InDesign.Application.CS")
Set myDocument = myInDesign.Documents.Add
Set myDocumentPreferences = myDocument.DocumentPreferences
Set myFileSystemObject = CreateObject("Scripting.FileSystemObject")
Rem Fill in the path to the folder containing the files you want to place.
Rem If you're add a user interface to this script, you can use a DirListBox
Rem to set the folder location.
Set myFolder = myFileSystemObject.GetFolder(myFolderName)
myNumberOfFrames = myFolder.Files.Count
myNumberOfPages = Round(myNumberOfFrames / myFramesPerPage)
If (myNumberOfPages * myFramesPerPage) < myNumberOfFrames Then myNumberOfPages = myNumberOfPages + 1
myDocumentPreferences.PagesPerDocument = CInt(myNumberOfPages)
myDocumentPreferences.FacingPages = False
Set myPage = myDocument.Pages.Item(1)
Set myMarginPreferences = myPage.MarginPreferences
myLeftMargin = myMarginPreferences.Left
myTopMargin = myMarginPreferences.Top
myRightMargin = myMarginPreferences.Right
myBottomMargin = myMarginPreferences.Bottom
myLiveWidth = myDocumentPreferences.PageWidth - (myLeftMargin + myRightMargin)
myLiveHeight = myDocumentPreferences.PageHeight - (myTopMargin + myBottomMargin)
myFrameWidth = myLiveWidth / myNumberOfColumns
myFrameHeight = myLiveHeight / myNumberOfRows
Set myPages = myDocument.Pages
Rem Construct the frames in reverse order. Don't laugh--this will
Rem save us time later (when we place the graphics).
For myCounter = myDocument.Pages.Count To 1 Step -1
Set myPage = myPages.Item(CInt(myCounter))
For myRowCounter = myNumberOfRows To 1 Step -1
myY1 = myTopMargin + (myFrameHeight * (myRowCounter - 1))
myY2 = myTopMargin + (myFrameHeight * myRowCounter)
For myColumnCounter = myNumberOfColumns To 1 Step -1
myX1 = myLeftMargin + (myFrameWidth * (myColumnCounter - 1))
myX2 = myLeftMargin + (myFrameWidth * myColumnCounter)
Set myRectangle = myPage.Rectangles.Add
myRectangle.GeometricBounds = Array(myY1, myX1, myY2, myX2)
Next
Next
Next
Rem Because we constructed the frames in reverse order, rectangle 1
Rem is the first rectangle on page 1, so we can simply iterate through
Rem the rectangles, placing a file in each one in turn.
myCounter = 1
Set myFiles = myFolder.Files
For Each File In myFiles
myPath = File.Path
myDocument.PageItems.Item(myCounter).Place myPath
myDocument.PageItems.Item(myCounter).Fit idFitOptions.idProportionally
myDocument.PageItems.Item(myCounter).Fit idFitOptions.idCenterContent
myCounter = myCounter + 1
Next
If myRemoveEmptyFrames = True Then
For Each Rectangle In myDocument.Rectangles
If Rectangle.ContentType = idContentType.idUnassigned Then
Rectangle.Delete
End If
Next
End If
I'll try to post a fancier one (i.e., one with a user interface) later.
Thanks,
Ole
Technical Details
Message-ID:
<2ccf346d.0@webx.la2eafNXanI>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!webxReferences:
<2ccf346d.-1@webx.la2eafNXanI>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f939a,b8a1bc58822e3cd3 X-Google-Attributes: gidf939a,public X-Google-ArrivalTime: 2004-01-05 15:07:50 PST From: Olav_Kvern@adobeforums.com Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!webx Newsgroups: adobe.scripting.indesign Subject: Re: Struggling with VBscript Message-ID: <2ccf346d.0@webx.la2eafNXanI> Date: Mon, 5 Jan 2004 14:59:30 -0800 References: <2ccf346d.-1@webx.la2eafNXanI> Lines: 91 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit