script newbie trying to work some magic

I'm trying to make a script to automatically align the pivots of selected objects, the align-part I've done but now i want the script to also create groups of each object(to sort of bypass aligning pivot axes to world). Here's what i've got so far:

for i in selection do
	(
		local NAME_IS = i.name 			--should be the name of the selected object
		local GROUP_EH =isGroupHead 	--check if selected object is a group
		if GROUP_EH = true then			--if it is a group
			(
				i.pivot.x = i.center.x			--move pivots of selected group
				i.pivot.y = i.center.y
				i.pivot.z = i.min.z
			)
		else
			(										--if selected object is not a group
				group i name:NAME_IS		--group it
				i.pivot.x = i.center.x			--and then move it's pivots
				i.pivot.y = i.center.y
				i.pivot.z = i.min.z
			)
		)

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
pixamoon's picture

`

But isn't enough to just ResetTransform ? It aligns pivot to world axes.

for i in selection do (
	i.pivot.x = i.center.x
	i.pivot.y = i.center.y
	i.pivot.z = i.min.z
	ResetTransform i
)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.