InDesign CS5 select all and move 10mm, repeating for each page

Hi,

As the subject suggests I’m trying to create a script for InDesign CS5 that selects all elements on the page and shifts them 10mm to the left. That is, changes the X position by -10mm. This action is then repeated for every other page in the document.

I’ve got as far as select all, but am stuck on shifting the elements to the left and repeating it for subsequent pages:

tell application "Adobe InDesign CS5"
	set myDocument to active document
	repeat with x from 1 to count pages of active document
		tell active document
			set ThisPage to page x
			tell ThisPage
				select all
			end tell
		end tell
		
	end repeat
	
end tell

Any help would be greatly appreciated.

Hi,

I guess it’s all Page items that you’ll need.
Never forget to set the measurement units that you expect …

tell application "Adobe InDesign CS3"
	tell active document
		
		set horizontal measurement units of view preferences to millimeters
		set vertical measurement units of view preferences to millimeters
		
		repeat with x from 1 to count pages
			set ThisPage to page x
			tell ThisPage
				move all page items by {-10, 0} --relative move x, y
			end tell
			
		end repeat
	end tell
	
end tell

(*
move‚v : Moves the object to a new location. Note: Either the to or the by parameter must be specified. Do not provide values for both parameters.
move specifier
to location specifier : The new location of the object.
[by number or text] : The amount to move the object relative to its current position, in the format [x, y].*)

Hi. I wrote a code sample for you, but you should really start out by reading Adobe’s InDesign scripting guide; it contains many helpful examples, as well as basic dictionary commands and explanations.

tell application "Adobe InDesign CS5"'s document 1
	repeat with pageNum from 1 to count pages by 2
		move page pageNum's page items by {-10, 0}--Assumed is your doc is measured in millimeters.
	end repeat
end tell

Edit: Hans beat me to it, but I think you intended to apply your change to every other page, so pay attention to the “by” in my repeat loop.

That’s great, almost perfect. I’ve discovered it fails (sort of) if an image is constrained within a text box. “Adobe InDesign CS5 got an error: This value would cause one or more objects to leave the pasteboard.” Is there a way round this?

Thanks for your help.

Thanks, Marc. To get round master page issues the document is converted to single pages so no need for every other page. I shall keep that tip for the future.

Hi,

I assume that the message for a item leaving the pasteboard is true.
So there’s probably no way moving it.

But you may use a move of single page items instead of a collection.
The one that errors will be ignored …

Have to say that I could only test with ID CS3

tell application "Adobe InDesign CS3"
	tell active document
		
		set horizontal measurement units of view preferences to millimeters
		set vertical measurement units of view preferences to millimeters
		
		repeat with x from 1 to count pages
			set ThisPage to page x
			tell ThisPage
				try
					set allPageItems to all page items
					move allPageItems by {-10, 0} --relative move x, y of a collection of page Items
				on error
					my findPageItem(allPageItems)
				end try
			end tell
			
		end repeat
	end tell
	
end tell

on findPageItem(arrayOfPageItems)
	repeat with i from 1 to count of arrayOfPageItems
		set theItem to item i of arrayOfPageItems
		tell application "Adobe InDesign CS3"
			set locked of theItem to false
			try
				move theItem by {-10, 0} --relative move x, y of a single page Item
			on error e
				display dialog e giving up after 5
			end try
		end tell
	end repeat
	end findPageItem

Thanks for your continued efforts, Hans.

There isn’t anything on the pasteboard. InDesign THINKS there is if you try and move the text box with an image inside of it. I suspect what your original script was doing was trying to move the picture box first, instead of the text box.

The second script will get round this but I wouldn’t be able to tell when something hasn’t moved. It’s kind of an all or nothing approach I’m looking for.

Can scripts do select all and a move?

Hello, again.
At issue could be the fact that there is special significance to the word “all” in InDesign; all page items is a property inclusive of anchored or inline elements. It may also be possible that your pasteboard isn’t sufficiently large to accommodate the requested change, and its size can be adjusted in the preferences.

If your move is being applied document-wide, there is no need for a repeat loop or a selection, which would slow performance.

tell application "Adobe InDesign CS5"'s document 1 to move page items by {-10,0}

Thanks, Marc, I was just about to post my discovery of just this solution. Thanks so much to both of you. Saved me no end of hassle.