Handling layers in Illustrator CS2 with Apple Script

Hi,

I have a Excel sheet with numeric Values in a row representing technical attributes of a mechanical system. I am setting these values of each row into variables. Then I would like to construct images in Adobe Illustrator CS2 by interpreting the Excel values by selecting/deselecting pre-built layers and objects in Illustrator.
Therefor, I wonder, if anybody could give me an advise how to handle following requirements:

  1. How can I select/deselect a certain layer by its name?
    Selecting a complete layer with all of its sublayer works fine with follwing code (another thread in this bulletin helped me, thanks):

tell application "Adobe Illustrator"
	activate
	set thisDoc to current document
	set selection to every page item of layer "test" of thisDoc
end tell

Unsolved…
2. How can I select/deselect a certain sublayer (“subtest”) in a layer (“test”)?
3. How can I rotate this previsously selected object?

Thank you very much in advance for any help.
Yours Aye,
Erden

Erden,

Took a while to get this but this is what I worked out. This is for CS1. I believe it will work in CS2. This is a recursive script, so it should be able to get to any sublayer that you have.

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

Let me know if this works for you.

PreTech

Hi PreTech,

sorry, it took me quite a lot time to get back to you. Thanks a lot, it helped me very much.
All the best,
Erden

Here is something fun I created dealing with hidden layers and lists. This script will create a list, show all hidden layers, then hide only those layers that were hidden to begin with. Have fun with it. I created it to be a part of a much larger script.

Levon


tell application "Adobe Illustrator"
	tell front document
		try --In case there are no hidden layers
			set hiddenLayers to name of every layer whose visible is false
			repeat with oneLayer in hiddenLayers
				set visible of layer oneLayer to true
			end repeat
			
			--Modify contents
			
			repeat with oneLayer in hiddenLayers
				set visible of layer oneLayer to false
			end repeat
		end try
	end tell
end tell

Model: Dual 2.3GHz G5
AppleScript: 2.1.1/Script Debugger 4
Browser: Firefox 2.0.0.6
Operating System: Mac OS X (10.4)