Working on a script that allows for a folder of images to be nominated then a document created with one image placed per page.
Here’s the script so far:
-- Determine source folder of images to be placed
tell application "Finder"
-- Select source folder
set srcfolder to choose folder with prompt "Select a folder of images to place in Indesign"
-- Count the number of images to place
set imageqty to count every item of folder srcfolder
-- display dialog imageqty & " images to place" as string giving up after 2
-- Create list of images to place
set PicList to every item of folder srcfolder
end tell
tell application "InDesign CS"
activate
-- Document Creation
set myDoc to make document
tell document preferences of myDoc
set page height to "297mm"
set page width to "210mm"
set page orientation to portrait
set pages per document to imageqty
end tell
-- Set Master Page Margins / Create picture box
tell page 1 of master spread 1 of myDoc
tell margin preferences
set top to 0
set left to 0
set bottom to 0
set right to 0
end tell
set mypicbox to make rectangle with properties {geometric bounds:{"10mm", "10mm", "287", "200mm"}}
end tell
-- Override rectangle of every page to allow for image to be placed
tell myDoc
repeat with i from 1 to imageqty
set applied master of page i to master spread "A-Master"
override rectangle 1 of master spread 1 destination page page i
end repeat
end tell
set ppnum to 1
-- Place images one page at a time from List
repeat with thisitem in PicList
-- display dialog thisitem as string
-- override rectangle picboxnum of master spread 1 destination page page 1
place thisitem on rectangle 1 of page ppnum
-- Thanks Shane Stanley Adobe Forums - for "on rectangle"
fit rectangle 1 given center content
-- Thanks Shane Stanley Adobe Forums - for "given center content"
set ppnum to (ppnum + 1)
end repeat
end tell
The script creates the correct number of pages based on the images selected , but doesn’t understand the "place thisitem on rectangle 1 of page… " command. Error generated is: “InDesign CS got an error: Can’t get rectangle 1 of page 1.”
There is only ONE rectangle on page 1. What am I doing wrong here?
If there is a standing / example script to do what I’m trying to achieve here I’d be grateful.
Ps. I have the Adobe InDesign Applescript Guide Pdf which is very useful but there is next to nothing in the 175pp guide that covers working with images and links. Is there another reference somewhere covering images in InDesign?
This works on my setup - I condensed your 2 repeat loops into one and tightened up a couple of other things. If you’re storing a bunch of items in a list, you don’t need a separate variable to count them!
When you’re placing a graphic, you have to call the rectangle you’re placing it on by page AND spread AND document. Like this: rectangle id 601 of page id 383 of spread id 258 of document “Untitled-19” (You can use the absolute page numbers instead - “page 1” instead of “page id 383.” The best clues about how to talk to InDesign come from watching what’s going on in the Event Log.
For some reason your original script was creating picture boxes that were way too big for the page, so I changed the fit parameters and that made it work better.
-- Determine source folder of images to be placed
tell application "Finder"
-- Select source folder
set srcfolder to choose folder with prompt "Select a folder of images to place in Indesign"
-- Count the number of images to place
set imageqty to count every item of folder srcfolder
-- display dialog imageqty & " images to place" as string giving up after 2
-- Create list of images to place
set PicList to every item of folder srcfolder as alias list
end tell
tell application "Adobe InDesign CS3"
activate
-- Document Creation
set myDoc to make document
tell myDoc
set horizontal measurement units of view preferences to millimeters
set vertical measurement units of view preferences to millimeters
tell document preferences of it
set page height to "297mm"
set page width to "210mm"
set page orientation to portrait
set pages per document to imageqty
end tell
end tell
-- Set Master Page Margins / Create picture box
tell page 1 of master spread 1 of myDoc
tell margin preferences
set top to 0
set left to 0
set bottom to 0
set right to 0
end tell
set mypicbox to make rectangle with properties {geometric bounds:{"10mm", "10mm", "287", "200mm"}}
end tell
-- Override rectangle of every page to allow for image to be placed
tell myDoc
repeat with i from 1 to imageqty
set applied master of page i to master spread "A-Master"
set thisRect to (override rectangle 1 of master spread 1 destination page page i)
place item i of PicList on thisRect
fit thisRect given frame to content
end repeat
end tell
end tell
There is no reference to the document in the line of code:
set thisRect to (override rectangle 1 of master spread 1 destination page page i)
BUT it works !! is this because it’s nested in the “tell myDoc” statement ??
I’m not sure exactly what part of my initial script I got wrong.
Added reference to Master Spread,but still got an error.
Error: get rectangle 1 of page 1 of master spread 1 of document “Untitled-23”
rectangle id 154 of page id 135 of master spread id 130 of document “Untitled-23”
“Can’t make «class crec» id 154 of «class page» id 135 of «class mspr» id 130 of document "Untitled-23" of application "InDesign CS" into the expected type.”
I suspected that there was a way to combine the 2 repeats but was focused more on getting it running initially. Thanks also for the repeat statement removing the need to count items, but rather process all of the items of the list. Makes sense.
Added :
-- fit image to frame
fit thisRect given proportionally
-- centre image in frame
fit thisRect given center content
Now images fit in the default frame and centre.
Next, l’ll tackle added source file names. Found a neat script from the Adobe site “Image Catalog”, as part of their downloadable sample scripts. I’ll try hacking this to get the remainder of my script working.
Yes - you’re already talking to myDoc because of the tell statement.
Not clear what you’re doing here or what the error is about. You know, you could just dispense with the master page business and simply step through the pages, create a new rectangle on each page with geometric bounds {whatever} and place the graphic in. It would make the script shorter and probably speed it up.
In case that last post didn’t make sense, here’s what I mean:
set myBounds to {"10mm", "10mm", "287", "200mm"}
-- Determine source folder of images to be placed
tell application "Finder"
-- Select source folder
set srcfolder to choose folder with prompt "Select a folder of images to place in Indesign"
-- Count the number of images to place
set imageqty to count every item of folder srcfolder
-- display dialog imageqty & " images to place" as string giving up after 2
-- Create list of images to place
set PicList to every item of folder srcfolder as alias list
end tell
tell application "Adobe InDesign CS3"
activate
-- Document Creation
set myDoc to make document
tell myDoc
set horizontal measurement units of view preferences to millimeters
set vertical measurement units of view preferences to millimeters
tell document preferences of it
set page height to "297mm"
set page width to "210mm"
set page orientation to portrait
set pages per document to imageqty
end tell
repeat with i from 1 to imageqty
set thisRect to (make rectangle of page i with properties {geometric bounds:myBounds})
place item i of PicList on thisRect
fit thisRect given frame to content
end repeat
end tell
end tell
Look how short it is now!
I like to put the geometric bounds in a variable, along with any other properties you might want to apply to the rectangle or its graphic (scale, rotation, etc).
Hi,
seems to work fine, but is it also possible to have 4 or 6 or 9 boxes on one page? How do I need to do that?
also, this script is configured as spread pages, I don’t like to have facing pages. How can I adjust it?
I’ve got a project coming up that requires exactly this script, so thanks for sorting it out for me. However, although I can use it as it is, I noticed that the script puts the two pictures for a spread together on the lefthand page. I can’t see how to modify the script to place subsequent images on the next page. Can anyone help?