Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Move selection to center of screen

Anonymous

Move selection to center of screen

Anonymous
Not applicable

Hi there,

 

At the company I work, we use a large library where when we import/merge a certain object, it is being imported at the 0.0.0 cordinate. I would like to have a command (shortcut too) in order to move the selection to the center of my screen. We would benefit very much if we could have this possibility. 

 

Looking forward to some comments,

 

Thanks in advance.

 

Best,

Remy

0 Likes
Reply
Accepted solutions (2)
2,264 Views
12 Replies
Replies (12)

Swordslayer
Advisor
Advisor

You can get the intersection of viewport center ray and the XY plane and move the object there:

 

fn getXYViewIntersection =
(
	local intersection = [0,0,0]
	local viewTM = inverse (viewport.getTM())
	manip.msXYPlane.intersect (ray viewTM.pos viewTM.row3) &intersection
	return intersection
)

$.pos = getXYViewIntersection()
0 Likes

Anonymous
Not applicable

Thank you for your reply and the code.

 

Maybe i am understanding it wrong or i did not made my intentions clear enough.

 

The idea of the script should actually be; that my current selection needs to be moved toward the center position of my screen (which won't be point 0.0.0), this could be any place in the XY world ofcourse. That i why i like the selection to be moved toward the center point of my screen.

 

What happens now is when i Evalluate the script, the my current selection will move to the point 0.0.0.

 

Hopefully I made it a bit more clear now. 

 

Thank you 🙂

 

 

0 Likes

Swordslayer
Advisor
Advisor

Maybe I misunderstood what you mean by center of the screen. The code will move the selection to the center of the active viewport, in all viewports default state, that is [0,0,0], if you pan the viewport, it's a different position. If you use a viewport where no intersection with XY plane is possible, replace XY in the code with a different plane.

0 Likes

Anonymous
Not applicable
Right guess that is what caused the miscommunication, my bad. What I have in mind is that when i am in top view, my selection will move toward the center of my screen (not center of viewport). Meaning that if i have a selection. I pan away, the code will move the selection toward the middle of my screen. I don't want my selection to go to the middle of the viewport indeed but really based on the position of my panning. So i can always move the selection toward my viewable screenview.
0 Likes

har1sf0x
Advocate
Advocate

Hello,

 

my wild guess is that he wants to pan the view and while the script evaluates the selected object should move only in the (x,y) plane of the orthographic view without changing the z value.

0 Likes

Swordslayer
Advisor
Advisor

@har1sf0x wrote:

Hello,

 

my wild guess is that he wants to pan the view and while the script evaluates the selected object should move only in the (x,y) plane of the orthographic view without changing the z value.


I'll just wait if he replies since this doesn't make sense to me in the previous context (problem being that imported objects are placed at the origin vs center of the screen).

0 Likes

Anonymous
Not applicable

haha, oke. I'm probably not clarifying myself enough. I'll attach two screenshots to explain it better.

 

So in the first picture, you see a top view. I've imported a model from our stock; it gets merged into the scene the at 0.0.0. and it stays selected.

 

In the second picture, I'm still in the top view but i have just panned a bit towards a side so that point 0.0.0 and the imported model are not visible anymore.

 

What i want the script to do is that when I evaluate the it; is that the selection will move towards the center of my second screen. The model only has to move on the X and Y axis. Not the Z axis because it doesn't need to move in the height.

 

I hope this clarifies things.

 

Thanks.

 

 

0 Likes

Swordslayer
Advisor
Advisor
Accepted solution

@Anonymous: umm... but... that's exactly what the script I originally posted does...

 

Edit: my mistake, it does that in every non-ortho viewport, so perspective is fine, top view is not. The reason is that in those cases, viewport position lies on the plane so intersection fails... oh well... to make it work, edit it this way:

 

fn getXYViewIntersection =
(
	local intersection = [0,0,0]
	local viewTM = inverse (viewport.getTM())
	manip.msXYPlane.intersect (ray (viewTM.pos + 10 * viewTM.row3) viewTM.row3) &intersection
	return intersection
)

$.pos = getXYViewIntersection()

Anonymous
Not applicable

Thank you!

 

Indeed this what I tried to achieve! Thank you very much.

 

Take care.

 

Remy

0 Likes

har1sf0x
Advocate
Advocate
Accepted solution

Hello again. 

I added @Swordslayer code the ability to evaluate in each view, orthographic or even perspective in the same manner.

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)
	)
return intersection
)
$.pos = getXYViewIntersection()

Enjoy

Anonymous
Not applicable

Ah indeed,

 

Great!

Thanks man!

0 Likes