Indesign CS3: select all items on layer "x"?

I want to do a copy/paste in place between two documents. Of course this works:


tell application "Adobe InDesign CS3"
	select all page items of page 1 of document 1
	copy
end tell

OK, but I want to just limit it to layer “x” and I’m following the ID Scripting guide which says I can address a layer by name. These fail:


tell application "Adobe InDesign CS3"
set myPageItems to items of layer whose name = "x" --< fails
set myPageItems to page items of layer whose name  = "x" --< fails
set myPageItems to items of layer whose name  = "x"  of page 1 --< fails
tell page 1
set myPageItems to items of layer whose name  = "x" of page 1 --< fails
select all page items of layer whose name = "x" --<fails
end tell --p1
	copy
end tell


Ultimately, I want to paste in place into a new document and then shift it by “y” amount for basic imposition.

thanx, sam

This works although I couldn’t target page 1. Not sure how to do that since it seems that you need to be talking to the document, not a page, to target a layer.

Maybe this will get you started:

tell application "Adobe InDesign CS3"
	select all page items of layer "x" of document 1
	copy
end tell

Model: iMac Intel 10.5.5
Browser: Firefox 3.0.2
Operating System: Mac OS X (10.5)

Hmm, a document attribute, not a page/spread.

Running your scriptlet as is errors with ID nnot finding the spread the object is on. So, I experimented with different spread/page enclosures. No love there. It either doesn’t like the “select” command, or get all page items because it cannot associate with the laser ‘x’.

It seems from my experience with ID that if I find a function in the program there’s normally a script to use it. I’m hoping for the script equivalent to "select item(s) on ‘x’ found in the layers pallette. I’m unsure what to try next, thanx, sam

Hi Sam,

You are actually looking for the item layer of the page item(s), not a page’s layer.

Hmmm. I played with item layer and couldn’t get anything out of it.

So, I messed around some more and got some more info but still can’t do what Sam is looking for.

tell application "Adobe InDesign CS3"
	tell document 1
		tell layer "Layer 2"
			set LayerID to id
		end tell
		
		tell page 1
			select all page items	
		end tell
		set theProps to (properties of selection)
	end tell
	
	set theParentInfo to (parent of (item 1 of theProps))
end tell

This gives me:
page id 179 of spread id 174 of document “Untitled-1” of application “Adobe InDesign CS3”

But I can’t seem to reference page ID 179 or spread ID 174 anywhere else without it erroring. Any ideas, anyone?

I don’t know why I am obsessed with this but I had to make it work.

Here is an admittedly very roundabout solution if you wanted to select only item on “Layer 1” on page 1 of spread 1 in your document.


tell application "Adobe InDesign CS3"
	tell document 1
		select page items of layer "Layer 1" --Select everything on "Layer 1" first
		set the layerID to item 1 of (item layer of selection) --get layer ID of "Layer 1"
		set theLayerIDList to {(item layer of (page items of page 1 of spread 1)), (page items of page 1 of spread 1)} --get list of the item layer and an object reference to all items on page 1 of spread 1
		
		--Now go through the list of items on page 1 and spread one, and if the layer ID doesn't match Layer 1, remove it from the current selection
		repeat with thecount from 1 to (count of item 1 of theLayerIDList)
			if (item thecount of item 1 of theLayerIDList) is not layerID then
				select (item thecount of item 2 of theLayerIDList) existing selection remove from
			end if
		end repeat
		
	end tell
	
end tell

I discovered in an old AppleScripting InDesign CS PDF book that Spread contains Page, but Layer is outside of Spread and Page so the only way was to go after the spread/page and then get a separate list based on layer and then compare them.

Model: iMac Intel 10.5.5
Browser: Firefox 3.0.2
Operating System: Mac OS X (10.5)

Yes, I’m glad you’re obsessed because this workaround works for single-page ID docs. More than one page I’m getting the error:

“Adobe InDesign CS3 got an error: Cannot determine the spread this object is on. It might be an anchored object that is in overset or uncomposed text.”

Of course, I’ve tried couching it within tell page 1 statement, but it kicks up this:

“Adobe InDesign CS3 got an error: every page item of layer "x" of page 1 of document 1 doesn’t understand the select message.”

I’m thinking the first error is a red herring but it cannot find it in a multipage doc. It ought to because we’re getting everything. But Script Editor gets to the third statement and it’s not even getting to the pages portion. It’s not getting everything it appears in the document.

unsure what to do next, sam

Hi

something along the lines of the below should help.

tell application "Adobe InDesign CS3"
	activate
	tell document 1
		set active layer to layer "X"
	end tell
	try
		set mySpread to spread 1 of active document
		select (every page item of page 1 of mySpread)
		copy
		paste in place
	end try
end tell

Budgie

I don’t recommend using any reference to spreads in conjunction with pages, as that will surely cause problems. Every page item has an item layer; you can define a group of items’ scope like this:

tell application "Adobe InDesign CS3"'s document 1
	page 1's page items whose item layer's name is "whatever you called it"
end tell

According to a chart I have showing the heirarchy of elements in InDesign, “Page” is contained by “Spread”. Is there a logical reason why you can’t use that or have you just experienced problems trying to do so? Just curious as it seems logical that it would work.

I could not for the life of me figure out how to use “item layer” so thanks for the example.

Model: iMac Intel 10.5.5
Browser: Firefox 3.0.2
Operating System: Mac OS X (10.5)

Thanks to all. This was more complicated that I thought. Which is why I’ve asked for help. This is one for the archives.

Here’s my implementation.

tell application "Adobe InDesign CS3"
	tell document 1
		set i to 1
		set a to page i's page items whose item layer's name is "x"
		select a
	end tell --doc 1
	copy
end tell