Reference Group Item Values in Illustrator

Hello,

I am trying to reference grouped items in illustrator by their actual value in the list via a variable but I get errors.

A script I found like this will work:

tell application "Adobe Illustrator"

set thisDoc to the current document
tell thisDoc

set plist to every group item

repeat with i in plist
set shapeSelection to every group item of layer "Shape Layer" of thisDoc
set position of i to {200, 200}
end repeat

end tell

But if I want to try and reference an individual group item in the plist, I get errors.

tell application "Adobe Illustrator"
	
	set td to the current document
	tell td
		
		set plist to every group item
		set itemcount to count of plist
                set maxcolumns to 4
		set maxrows to (itemcount div maxcolumns)
		set remainder to (itemcount mod maxcolumns)
		set pageitem to 1
		set currentrow to 0
		
		
		repeat until currentrow = maxrows
			
			set currentcolumn to 0
			
			repeat until currentcolumn = maxcolumns

				set position of group item pageitem in plist to {(200 * currentcolumn), (200 * currentrow)}
				set pageitem to (pageitem + 1)
				set currentcolumn to currentcolumn + 1

			end repeat
			
			set currentrow to (currentrow + 1)
			
		end repeat
		
	end tell
end tell

Rather than using a repeat with i in plist, I want to control the layout of the “table” by referencing the current item number in the list through iterations.

The items in the document are also grouped, and need to be referred to as such (otherwise individual elements get moved instead).

Any help would be greatly appreciated.

Thanks.

You are likely running into a hidden detail of AppleScript internals (the query/response underpinnings of how AppleScript uses AppleEvents to talk to applications). Application specific reference forms can not (generally) be applied to AppleScript lists (only to references to application objects). Usually one just uses the item N of listvar reference form to access items of a list once it is on the AppleScript side. Try this wording:

tell application "Adobe Illustrator"
.
		set plist to every group item
.
				. item pageitem in plist .
.
end tell

Incidentally, you may not have to use row and column based loops. It looks like you might be able to compute the row and column number for each index instead:

tell application "Adobe Illustrator"
	set td to the current document
	tell td
		set itemcount to count every group item
		set maxcolumns to 4
		set remainder to (itemcount mod maxcolumns)

		repeat with pageitem from 1 to itemcount - remainder
			set currentcolumn to (pageitem - 1) mod maxcolumns
			set currentrow to (pageitem - 1) div maxcolumns
			set position of group item pageitem to {(200 * currentcolumn), (200 * currentrow)}
		end repeat
	end tell
end tell

Edit History: Made second example consider remainder.