lesson 13 started talking about how to script the contents of documents — specifically, how to select items on a page. let’s continue by having a look at some things you can do with page items.
if you want to follow along — open a new document and put a bunch of different page items on the first page — make sure you have more than one ‘rectangle’ (text frames are not rectangles — even if they are rectangular). then run this script from script editor (found in applications > applescript) — as always, update the script to your version of Indesign :
tell application "Adobe InDesign CS4" activate tell active document select every rectangle of page 1 move selection by (5,1) end tell end tell
the numbers in the brackets are the X (horizontal) and Y (vertical) locations and the unit increments will be whatever you have set as your default. you could replace those two lines with this instead if you like :
move rectangles of page 1 by (5,1)
notice the difference? the rectangles are moved without having to select them first. if you want to include items on the pasteboard, use this instead :
move rectangles of spread 1 by (5,1)
contrast the ‘move by’ command with the results of ‘move TO’ :
move rectangles of page 1 to (5,1)
which is similar to when you try to move items to a new page :
move rectangles of page 1 to page 2
that’s a problem if you want your page items to maintain their relative positions. you could get around the first problem like this :
tell application "Adobe InDesign CS4" activate tell active document select rectangles of page 1 set newGroup to make group with properties {group items:selection} move newGroup to {5, 1} ungroup newGroup end tell end tell
… and the second problem like this :
tell application "Adobe InDesign CS4" activate tell active document select rectangles of page 1 end tell cut tell active document set newPage to page 2 tell layout window 1 set active page to newPage end tell end tell paste in place end tell
notice in this one how you can not tell a document to cut and paste — you have to tell the application. when developing your own scripts, once you get a script like this to work — it’s a good idea to go back through it to see if it can be streamlined. here’s one way to simplify the previous script :
tell application "Adobe InDesign CS4" activate select rectangles of page 1 of active document cut set newPage to page 2 of active document set active page of layout window 1 of active document to newPage paste in place end tell
this next script demonstrates a few other commands. before running it, make sure you have at least two rectangles on page 2. can you work out how InDesign determines which is rectangle 1 and which is rectangle 2? :
tell application "Adobe InDesign CS4" activate tell page 2 of active document set horizontal scale of rectangle 1 to 150 set rotation angle of rectangle 1 to 10 set stroke weight of rectangle 1 to 10 set stroke color of rectangle 1 to "Paper" set shadow mode of rectangle 1 to drop set vertical scale of rectangle 2 to 200 set fill color of rectangle 2 to "Black" set shear angle of rectangle 2 to 20 set feather mode of rectangle 2 to standard set feather width of rectangle 2 to 5 end tell end tell
that’s it for now. the next lesson will show how to make new page items.