illustrator layer problem

here we go…

I have several page items with the same name that I want to duplicate from document to document 2 (which has all the same layers)
when they are duplicated they need to stay on the same layers. I can do that like this


tell application "Adobe Illustrator"
	set theobjects to (every page item of document 1 whose name is AnItem)
	repeat with anObject in theobjects
		set aLayer to layer of anObject
		duplicate anObject to layer aLayer of document 2
	end repeat
end tell

the problem comes in when the page item is on a sublayer and and who knows how many layers deep it may be. if the page item is 3 layers deep I would have to get all the layer names and add them in sort of like this


tell application "Adobe Illustrator"
	set theobjects to (every page item of document 1 whose name is AnItem)
	repeat with anObject in theobjects
		set aLayer to layer of anObject
		duplicate anObject to layer aLayer of layer layer 1 of layer 2 of layer 1 of document 2
	end repeat
end tell

any help would be apreciated

illustrator has a preference in the flyout menu of layers for “paste remember layers” this also works for C&P in script if that is any use to you. Does not work with duplicate to target nor can I find how to set or detect this option even though it works sweet. You’ll just need to get the bounds to position I think.

Mark,

thanks fo the suggestion however, cut an paste is not an option for me although that would work. infect I wold not need to figure out its position as long as I did a paste infront.

mm

mm,

This is a script I posted for someone else a while back. It is written for CS1 but I believe should work for CS2 also. This uses recursion to get to the bottom layer of any number of layers. This is just an example of the recursion. I haven’t looked at this script for a while so you will have to look at it and see if it is of any use, but I believe it will help. You may have to have your script make new layers in the new document (if that is necessary) by using a list to keep track of where the layers are in relation to each other. Hope this is of some help.

PreTech

global theLayers, layerNames
set theLayers to {}
set layerNames to {}
tell application "Illustrator CS"
	set l to every layer of current document
	repeat with aLayer in l
		if (count of layers of aLayer) is not 0 then
			set s to every layer of aLayer
			set theLayers's end to aLayer
			set layerNames's end to name of aLayer
			my getLayers(s)
		end if
	end repeat
	set theChoice to (choose from list layerNames) as text
	--display dialog theChoice
	repeat with anLayer in l
		if name of anLayer is theChoice then
			set selection to every page item of anLayer of current document
			exit repeat
		else
			set s to every layer of anLayer
			my selectLayers(s, theChoice)
		end if
	end repeat
end tell

on getLayers(sub)
	tell application "Illustrator CS"
		repeat with aLayer in sub
			if (count of aLayer) is not 0 then
				set morS to every layer of aLayer
				set theLayers's end to aLayer
				set layerNames's end to name of aLayer
				my getLayers(morS)
			end if
		end repeat
	end tell
end getLayers

on selectLayers(sub2, theName)
	tell application "Illustrator CS"
		repeat with aLayer in sub2
			if name of aLayer is theName then
				set selection to every page item of aLayer
				rotate selection angle 90 -- this will rotate each item in the selection 90 degrees about its [b]own[/b] axis. If all items are to be rotated while keeping their angles the same with respect to each other, you'll need to group those items. 
				exit repeat
			else
				if (count of aLayer) is not 0 then
					set morS to every layer of aLayer
					my selectLayers(morS, theName)
				end if
			end if
		end repeat
	end tell
end selectLayers

pretech,

that was extremely helpful thank you :smiley:

Glad to hear it helped! You’re welcome.:slight_smile:

PreTech