Illustrator - center align objects

Hello,

I have a series of circles on one layer, and a series of squares on another layer. I want these two groups of items to center align on the vertical axis.

I do not need them to align on the horizontal axis, nor do I need these two groups to stack on top of each other at the center of the page.

My problem is my script is getting the visible bounds of both groups combined and centering that, instead of center aligning the circle group and then center aligning the square group.

Can someone please help me figure out where I went wrong? Thank you!


tell application "Adobe Illustrator"
	
	set thisDoc to the current document
	tell thisDoc
		
		set pageWidth to width
		set pageHeight to height
		
		set ruler origin to {(pageWidth / 2), (pageHeight / 2)}
		set {leftEdge, topEdge, rightEdge, bottomEdge} to visible bounds
		
		set circleSelection to every group item of layer "Circles" of thisDoc
		translate circleSelection delta x -((leftEdge + rightEdge) / 2)
		
		set squareSelection to every group item of layer "Squares" of thisDoc
		translate squareSelection delta x -((leftEdge + rightEdge) / 2)
		
	end tell
end tell

Hi

Not sure what your set-up is exactly but i had some success with this
i hope i’m on the right track:

tell application "Adobe Illustrator"
	set td to the current document
	tell td
		set w to width
		set h to height
		set ruler origin to {(w div 2), 0}
		set plist to page items
		repeat with i in plist
			set gw to width of i
			set p to position of i
			set position of i to {0 - (gw / 2), item 2 of p}
		end repeat
	end tell
end tell

Thank you Pidge. I suspected I needed a repeat loop in there but wasn’t sure how to set it up. :slight_smile:

I think I still need a little modification or clarification (or some other “-ation”). I have two layers, each with a group of items. One is called “Circles” and contains 6 different sized circles. Same thing for my layer called "Squares, " there are 6 squares, different sizes. I need to be able to see every square and circle.

When I run your script all my items get ungrouped and stacked on top of each other. For example, if I had a string of letters “A B C D E F” that were converted to vector outlines, and I ran this script, they all get stacked on top of each other and are unreadable.

Hmmm…

Aha! I figured it out. I just needed to change:


set plist to page items

to


set plist to every group item

Pidge, you rock, thanks for sharing your help and have a great day
-Clobberella