Grouping objects in Adobe Illustrator

Hi all,

I want to select every page item in an Illustrator document and put it in a group. Sounds simple enough but it seems I can only select every path item or every raster item and so forth, which are all subclasses of page items.

If I use the term “page item”, I get an error: “Adobe Illustrator got an error: an Illustrator error occurred: 1346458189 (‘MRAP’)”

Any ideas? My code is below.
David


tell application "Adobe Illustrator"
	tell current document
		set MyGroup to make new group item
		set MySelection to every path item -- every raster item also works, but not page item
		move MySelection to end of MyGroup
	end tell
end tell

Your problem is that if you select every page item, you select the group as well – and you can’t move a group into itself. You need to do something like make the group then move pages items 2 thru -1, or make your group at the end and move page items 1 thru -2.

Hi Shane,

thanks, that makes total sense.

I tried the following where I copied all page items to a variable before creating the new group but I still get an error: “Adobe Illustrator got an error: Can’t get path item 1 of group item 1 of layer 1 of document 1”. Maybe it’s because I’m trying to move items within groups as well as the groups into the new group…?


tell application "Adobe Illustrator"
	tell current document
		set EveryPageItem to every page item
		set MyGroup to make new group item
		move EveryPageItem to end of MyGroup
	end tell
end tell

There are two issues.

First, don’t use a variable. The problem is that using variable means you end up with references to the items, which are all index based. Then when you create a new item, all the indexes are out by 1 (unless you create it at the end of the other other items). It’s also slower; you’re making Illustrator do unnecessary work building references.

Second, you’re right about items within groups. You can effectively flatten the hierarchy by referring to items by layer like this:

page items 2 thru -1 of every layer

Brilliant! Thanks so much again Shane, this works a charm.


tell application "Adobe Illustrator"
	tell current document
		set MyGroup to make new group item
		move page items 2 thru -1 of every layer to end of MyGroup
	end tell
end tell