working with subgroups and sublayers in illustrator

hey guys, i’m a little lost on this one. I’m working with Adobe Illustrator CC and i’m ultimately trying to identify a subgroup of a layer by name and turn of visibility to all other items except for that subgroup. I don’t have much to show in the way of scripting because i haven’t really gotten off the ground yet. I can easily get the name of the main layers but I’m having trouble finding a way to get the names of the sublayers and subgroups in those layers. In searching i have seen examples that make a list of the main layers and then run a repeat on the “layers of layer i” to get further info on sublayers but that always returns empty results for me. Can anyone point me in the right direction for being able to generate a list of subgroups inside of a layer?

Hi dsetter,

I created an Illustrator document with 3 layers.
The top layer was called ‘the-top-layer-name’, and this contained 2 sub-layers called ‘sub-layer-1’ and ‘sub-layer-2’.

I used the code below to switch the visibility of the required sub-layer on and off.


tell application "Adobe Illustrator"
	activate
	set visible of layer "sub-layer-2" of layer "the-top-layer-name" of front document to true
end tell

Is that the sort of structure you have within your document?

You could use to get a list of sub-layers, contained within ‘the-top-layer-name’. You could then loop through the list, to check the names of the sub-layers one by one, and set the visibility accordingly.


tell application "Adobe Illustrator"
	activate
	set subLayers to layers of layer "the-top-layer-name" of front document
end tell

… and looping through layers…


tell application "Adobe Illustrator"
	activate
	
	set theFrontDoc to front document
	set theTopLevelLayerName to "the-top-layer-name"
	set theLayerException to "sub-layer-2"
	set theLayerVisibiltyOnOff to false
	
	set theLayersList to every layer of layer theTopLevelLayerName of theFrontDoc
	
	repeat with thisLayer in theLayersList
		
		set thisLayerName to (name of thisLayer as text)
		
		if thisLayerName ≠ theLayerException then
			set visible of layer thisLayerName of layer theTopLevelLayerName of theFrontDoc to theLayerVisibiltyOnOff
		end if
		
	end repeat
	
end tell


HTH

Thanks for the help. I feel like i have to be missing something dumb. Your script looks a lot like the examples I found that I couldn’t get to work. I modified the script to reflect my AI file and tried it. It runs but does nothing. When I put a return in there to see what it’s generating as a list, i get results of {}.


tell application "Adobe Illustrator"
	activate
	
	set theFrontDoc to front document
	set theTopLevelLayerName to "Layer 2"
	set theLayerException to "<Group>"
	set theLayerVisibiltyOnOff to false
	
	set theLayersList to every layer of layer theTopLevelLayerName of theFrontDoc

	return theLayersList

	repeat with thisLayer in theLayersList
		
		set thisLayerName to (name of thisLayer as text)
		
		if thisLayerName ≠ theLayerException then
			set visible of layer thisLayerName of layer theTopLevelLayerName of theFrontDoc to theLayerVisibiltyOnOff
		end if
		
	end repeat
	
end tell


I have confirmed that my layer names are correct and can effect those layers, but still nothing for any sub layers.

Hhhmmm?

In the test document I created I had 5 layers.
The top level layer was named ‘the-top-layer-name’.
That layer had the sub-layers ‘sub-layer-1’, ‘sub-layer-2’, ‘sub-layer-3’ & ‘sub-layer-4’.

Is that the sort of structure you have in yours?

Hi dsetter,

Illustrator is very gracious to work with once you get inside it’s head / way of thinking. Maybe a first step is to make sure you are addressing layers in a way that it understands. Try this example and see what comes back as both the references, and the names, that your document contains:


tell application "Adobe Illustrator"
	activate
	
	set theFrontDoc to front document
	
	set theLayersList to every layer of theFrontDoc
	set theLayersNameList to the name of every layer of theFrontDoc
	
	return theLayersList
	
end tell