Retaining object hierarchy when duplicating multiple items at once

Is there a way to maintain object hierarchy when duplicating multiple items (up to 250 separate items) from a selection? I know Applescript keeps the layer the object was on intact, but it is putting some items below other items during the duplication process. Thanks for your help!

Adam

Hi, Adam. I’ll assume you are talking about InDesign, as that was to what your most recent question pertained. If you don’t specify a location, the duplicate should always dupe to above the existing item, however, using a selection might complicate things”especially if you are grouping items on the fly”as an item with a higher index could be paired with a lower one outside creation order; selections use selection order, and they are, in general, to be avoided in good scripting.

Thanks for your reply. Yes, this is InDesign CS4 I am working in.

I actually figured out that the selection was getting every object (makes perfect sense, duh) and not the group that each object belonged to. I was able to filter the objects out whose parent’s class wasn’t “page”.

So that part is now working, but I am having a problem with the duplicate method. It wants to duplicate the item right into the spot it came from. This is a problem for me because I am creating a new document that doesn’t have the same dimensions. Basically, the source document is comprised of 3 pages that need to be broken out into individual pages. Page 1 goes from 0" to 11", page 2 from 11" to 24", and page 3 from 24" to 31". So, for page 1, the duplicate method works perfect, no problems. Page 2, the objects aren’t on the page at all, but they are on the pasteboard. Page 3, there is nothing, because it is too far off the pasteboard to even be in the document.

Any suggestions on how to get the page 2 and page 3 to duplicate to the new page and be on the page?

Thanks!

Adam

Sorry, I thought it would be helpful to post my script for your review as well.


set myDocument to "Untitled:Users:ajriggs:Desktop:DimensionTestDocument.indd"
tell application "Adobe InDesign CS4"
	open myDocument
	set originalDocument to active document
	set myPage to page 1 of active document
	set myPageHeight to page height of document preferences of active document
	
	set allPageDimensions to page item "page divider" of myPage
	--display dialog allPageDimensions
	if (count of items of allPageDimensions) = 3 then
		--display dialog "This is a six page ad"
		set box1myX1 to item 2 of geometric bounds of item 1 of allPageDimensions
		set box2myX1 to item 2 of geometric bounds of item 2 of allPageDimensions
		set box3myX1 to item 2 of geometric bounds of item 3 of allPageDimensions
		
		--get page 1 by geometric bounds
		if box1myX1 < box2myX1 then
			if box1myX1 < box3myX1 then
				set myPage1 to item 1 of allPageDimensions
				--set fill color of myPage1 to "Black"
				set remainingPages to {item 2 of allPageDimensions, item 3 of allPageDimensions}
			end if
		else if box2myX1 < box3myX1 then
			set myPage1 to item 2 of allPageDimensions
			--set fill color of myPage1 to "Black"
			set remainingPages to {item 1 of allPageDimensions, item 3 of allPageDimensions}
		else
			set myPage1 to item 3 of allPageDimensions
			--set fill color of myPage1 to "Black"
			set remainingPages to {item 1 of allPageDimensions, item 2 of allPageDimensions}
		end if
		
		--determine page 2 and 3 by geometric bounds
		set box1myX1 to item 2 of geometric bounds of item 1 of remainingPages
		set box2myX1 to item 2 of geometric bounds of item 2 of remainingPages
		
	
		
		if box1myX1 < box2myX1 then
			set myPage2 to item 1 of remainingPages
			--set fill color of myPage2 to myColorA
			set myPage3 to item 2 of remainingPages
			--set fill color of myPage3 to myColorB
		else if box2myX1 < box1myX1 then
			set myPage2 to item 2 of remainingPages
			--set fill color of myPage2 to myColorA
			set myPage3 to item 1 of remainingPages
			--set fill color of myPage3 to myColorB
		end if
	end if
	
	--Get the Dimensions of the different pages within the document
	--Get Dimensions of page 1
	set page1X1 to (item 4 of geometric bounds of myPage1)
	set page1x2 to (item 2 of geometric bounds of myPage1)
	set page1y1 to (item 1 of geometric bounds of myPage1)
	set page1y2 to (item 3 of geometric bounds of myPage1)
	set page1Width to (page1X1 - page1x2)
	
	--Get Dimensions of page 2
	set page2X1 to (item 4 of geometric bounds of myPage2)
	set page2x2 to (item 2 of geometric bounds of myPage2)
	set page2Width to (page2X1 - page2x2)
	
	--Get Dimensions of page 2
	set page3X1 to (item 4 of geometric bounds of myPage3)
	set page3x2 to (item 2 of geometric bounds of myPage3)
	set page3Width to (page3X1 - page3x2)
	

	
	tell active document
		set selectForPage1 to (every item of all page items of page 1 where item 1 of its geometric bounds is greater than page1x2 and item 1 of its geometric bounds is less than page1y2 and item 2 of its geometric bounds is greater than page1y1 and item 2 of its geometric bounds is less than page1X1 and parent's class is page)
		
		set selectForPage2 to (every item of all page items of page 1 where item 1 of its geometric bounds is greater than page1y1 and item 1 of its geometric bounds is less than page1y2 and item 2 of its geometric bounds is greater than page2x2 and item 2 of its geometric bounds is less than page2X1 and parent's class is page)
		
		set selectForPage3 to (every item of all page items of page 1 where item 1 of its geometric bounds is greater than page1y1 and item 1 of its geometric bounds is less than page1y2 and item 2 of its geometric bounds is greater than page3x2 and item 2 of its geometric bounds is less than page3X1 and parent's class is page)
		
		
	end tell
	
	
	
	set newPage1 to make document with properties {document preferences:{page width:page1Width, page height:myPageHeight}}
	set newPage2 to make document with properties {document preferences:{page width:page2Width, page height:myPageHeight}}
	set newPage3 to make document with properties {document preferences:{page width:page3Width, page height:myPageHeight}}
	
	
	tell originalDocument
		
		repeat with anItem in selectForPage1
			tell anItem
				duplicate to page 1 of newPage1
			end tell
		end repeat
		
		repeat with anItem in selectForPage2
			tell anItem
				duplicate to page 1 of newPage2
			end tell
		end repeat
		
		repeat with anItem in selectForPage3
			tell anItem
				duplicate to page 1 of newPage3
			end tell
		end repeat
	end tell
	
	
end tell

I got this working too! I just had to combine the duplicate with the move command. Worked like a charm.