Move group to center of screen

Hi,

So i actually already have a script that works a bit like this. The problem is that it only works for a single object/proxy.

What i would like is to be able to select a group - run the script - and that the group moves to the center of my viewport.

What happens now is that all the object within the group are move to a single point too. I like to maintain the structure of the group.

Hopefully somebody can help me improve the current script.

Thank you.

AttachmentSize
center_proxy.ms950 bytes

Comments

Comment viewing options

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

*

I noticed that when you select multiple groups/objects, that not all get centered but just one of them. Could this might improved in order to make it work with multiple selected objects/groups?

Thank you :)

miauu's picture

.

(
	fn getXYViewIntersection =
	(
		local intersection = [0,0,0]
		local viewTM = inverse (viewport.getTM())
		case (viewport.getType()) of 
		(
			#view_left: (manip.msYZPlane.intersect (ray (viewTM.pos + 10 * viewTM.row3) viewTM.row3) &intersection)
			#view_right: (manip.msYZPlane.intersect (ray (viewTM.pos + 10 * viewTM.row3) viewTM.row3) &intersection)
			#view_top: (manip.msXYPlane.intersect (ray (viewTM.pos + 10 * viewTM.row3) viewTM.row3) &intersection)
			#view_bottom: (manip.msXYPlane.intersect (ray (viewTM.pos + 10 * viewTM.row3) viewTM.row3) &intersection)
			#view_front: (manip.msXZPlane.intersect (ray (viewTM.pos + 10 * viewTM.row3) viewTM.row3) &intersection)
			#view_back: (manip.msXZPlane.intersect (ray (viewTM.pos + 10 * viewTM.row3) viewTM.row3) &intersection)
			default: (manip.msXYPlane.intersect (ray (viewTM.pos + 10 * viewTM.row3) viewTM.row3) &intersection)
		)
		intersection
	)
 
	function FindTopMostGroupHead obj = if isgroupMember obj do
	(
		while obj != undefined and (not isGroupHead obj or isGroupMember obj) do
			(obj = obj.parent)
		obj
	)
 
	if selection.count != 0 do
	(
		selObjsArr = selection as array
		objsArr = #()
		for o in selObjsArr do
		(
			grpHead = FindTopMostGroupHead o
			if grpHead == undefined then
			(
				append objsArr o 
			)
			else
			(
				appendifUnique objsArr grpHead
			)
		)
		for o in objsArr do
		(
			o.pos = getXYViewIntersection()
		)
	)
)
miauu's picture

.

(
	fn getXYViewIntersection =
	(
		local intersection = [0,0,0]
		local viewTM = inverse (viewport.getTM())
		case (viewport.getType()) of 
		(
			#view_left: (manip.msYZPlane.intersect (ray (viewTM.pos + 10 * viewTM.row3) viewTM.row3) &intersection)
			#view_right: (manip.msYZPlane.intersect (ray (viewTM.pos + 10 * viewTM.row3) viewTM.row3) &intersection)
			#view_top: (manip.msXYPlane.intersect (ray (viewTM.pos + 10 * viewTM.row3) viewTM.row3) &intersection)
			#view_bottom: (manip.msXYPlane.intersect (ray (viewTM.pos + 10 * viewTM.row3) viewTM.row3) &intersection)
			#view_front: (manip.msXZPlane.intersect (ray (viewTM.pos + 10 * viewTM.row3) viewTM.row3) &intersection)
			#view_back: (manip.msXZPlane.intersect (ray (viewTM.pos + 10 * viewTM.row3) viewTM.row3) &intersection)
			default: (manip.msXYPlane.intersect (ray (viewTM.pos + 10 * viewTM.row3) viewTM.row3) &intersection)
		)
		intersection
	)
 
	function FindTopMostGroupHead obj = if isgroupMember obj do
	(
		while obj != undefined and (not isGroupHead obj or isGroupMember obj) do
			(obj = obj.parent)
		obj
	)
 
	if selection.count != 0 do
	(
		grpHead = FindTopMostGroupHead selection[1]
		if grpHead == undefined then
		(
			selection[1].pos = getXYViewIntersection()
		)
		else
		(
			grpHead.pos = getXYViewIntersection()
		)
	)
)
remykonings's picture

Thank you. That works great

Thank you. That works great :)

Comment viewing options

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