Selecting layers with > 1 object and then grouping lllustrator CS


Is there a way to script a condition to select an individual layer that has more than 1 sublayer, grouping it, then selecting the next layer that has more than 1 sublayer and grouping it and so on? I could only find help with grouping all layers. :o

When you say “grouping it”, what do you mean?

Illustrator grouping - like command + G. Does that make sense? My apologies.

But grouping what exactly?

Ohhh, I see! Sorry, just started trying this jazz two days ago (I’m generally slow on top of that). Illustrator vector art objects + outlined text (same thing?) + embedded images.

You’re still not clear on what you want to group. The items in a group are, by definition, on the same layer. You’re talking about sublayer. So are you saying that if a layer has sublayers, you want all the items moved to the main layer and everything grouped together?

Yes! My apologies.

I think this is what you’re asking for:

tell application id "com.adobe.illustrator" -- Adobe Illustrator
	tell document 1
		repeat with i from 1 to count of layers
			set oneLayer to layer i
			set sublayerCount to count of layers of oneLayer
			if sublayerCount > 0 then
				repeat with j from 1 to sublayerCount
					move every page item of layer j of oneLayer to end of oneLayer
				end repeat
				set newGroup to make group item at beginning of oneLayer
				move page items 2 thru -1 of oneLayer to end of newGroup
			end if
		end repeat
	end tell
end tell