Modify PERSPECTIVE detail-view in layout

good afternoon,

is there a way to expand or crop a detailed - perspective - view in layout?
I cant figure out how to do this simple task.

I have a perspective view which shows a part of a model in a certain view-angle.
When I put this detail-view onto a layout because I look at it from below the shown geometry is more on the upper part of the picture-frame.
Now I want to rearrange it on the layout so that it sits in the middle and want to expand the upper edge of the detail-view to my border and crop the bottom part to the border - simple as that.

  • But when I do this the view scales in size.

as a workarround I now had to create a hatch with the same color as the background of the viewport-mode add it on top of the layout and make a white border-hatch arround the image so that the background of the viewport-mode does not show till the bottom of the layout.

I attached you a file - wondering why this has to be that complicated? I can crop fine when the view is isometric.

BONUS: Is there a setting that shows the background color of my viewport-mode in the layout view? Now I have to click it to see the full picture.

FILE:
Expanding_Cropping_Detailview_in_Layout.3dm (9.0 MB)

best regards,
sebowim

1 Like

You can click on the detail view boundary and turn the control points on. Does that help?

After you have the detail view sized and positioned, you can activate the view so that you can position the camera frustum per say to view your 3D model however you want, I think. :thinking:

I’m pretty sure the axonometric angle shouldn’t be the culprit here. But I have seen some bugs earlier this year with things like grid and background color. It’s possible both problems were fixed, but I haven’t verified.

You can set the display mode of the detail view to embody the background characteristics you’d like to see.

Although I have seen bugs before relative to that, and haven’t tested it lately.

@lander thank you for your help but unfortunately I have already tried that and it seems it does not work.

For clarification - I want the the detail-views border (red-lines) to be were the green-lines are BUT the position of the object should not move.

The behaviour now is that when I do this it just moves everything up.

Thank you,
sebowim

PS: the display mode of the detail-view IS set to the red background but it only shows when I open (double click) the detail-view. When its closed (locked) its plain white like in the first picture - its the same display-mode

hmm, k well, you might have to adjust it afterwards?

Maybe make a named view that you can use to set the specific parameters, idk.

This sounds similar to a bug I’ve seen, but I can’t remember if it was grid related only or background related also.

I’m not familiar with this. Might be a new feature.

I’m not sure how much time I’ll have to test this, but this is what I see so far:

And I’m not sure what display mode you’re using on your end, but you may want to upload that if you can, so others can test that specific version too.

Interesting. Not sure if there’s a way to map the angles into the camera frustum or something. :thinking:

Here is a script you can use to crop a perspective detail view. It adjusts the camera target and lens length to the appropriate values to best match the previous. (There will be slight differences if the new center of the detail is different from the old center, but it will try to match approximately.)

import Rhino
from Rhino.Geometry import Vector3d
import rhinoscriptsyntax as rs

def crop_perspective_view():
	# user input
	detail = rs.GetObject("Detail to crop", filter=32768, preselect=True)
	if not detail:
		print("Cancel")
		return
	rect = rs.GetRectangle(mode=1)
	if not rect:
		print("Cancel")
		return

	rs.EnableRedraw(False)

	# resize detail
	rs.EnableObjectGrips(detail)
	rs.SelectObjectGrips(detail)
	grips = rs.SelectedObjectGrips(detail)
	grips = [grips[i] for i in (2,6)]
	grip_pts = [rs.ObjectGripLocation(detail, grip) for grip in grips]
	detail_center = (grip_pts[0] + grip_pts[1])/2
	detail_size = min(grip_pts[1].X - grip_pts[0].X, grip_pts[1].Y - grip_pts[0].Y)
	rect_center = (rect[0] + rect[2])/2
	rect_size = min(rect[0].DistanceTo(rect[1]), rect[1].DistanceTo(rect[2]))
	offset_x = rect_center.X - detail_center.X
	offset_y = rect_center.Y - detail_center.Y
	new_points = [rect[i] for i in (0,2)]
	for grip, new_point in zip(grips, new_points):
		rs.ObjectGripLocation(detail, grip, new_point)
	rs.EnableObjectGrips(detail, False)

	# model space
	layout = rs.CurrentView(return_name=False)
	rs.CurrentDetail(layout, detail)
	if rs.ViewProjection() == 2:
		old_camera, old_target = rs.ViewCameraTarget()
		old_lens = rs.ViewCameraLens()
		old_depth = old_camera.DistanceTo(old_target)
		old_size = old_depth*24/old_lens
		up = rs.ViewCameraUp()
		normal = Vector3d(old_camera - old_target)
		xaxis = Vector3d.CrossProduct(up, normal)
		old_plane = rs.PlaneFromNormal(old_target, normal, xaxis)

		# calculate updates
		target_delta = old_plane.XAxis*offset_x + old_plane.YAxis*offset_y
		target_delta *= old_size/detail_size
		new_camera = old_camera
		new_target = old_target + target_delta
		new_lens = old_lens*detail_size/rect_size

		# apply updates
		previous_lock = rs.DetailLock(detail, False)
		rs.ViewCameraTarget(camera=new_camera, target=new_target)
		rs.ViewCameraLens(length=new_lens)
		rs.DetailLock(detail, previous_lock)
	rs.CurrentDetail(layout, layout)
	rs.SelectObject(detail)

	rs.EnableRedraw(True)

if __name__ == "__main__":
	crop_perspective_view()

4 Likes

sorry I totally forgot to upload the displaymode here you go:
SW_flat1.ini (14.1 KB)

and yes your video shows exactly what I mean.

Does else know why this behaviour is like this? @wim ? feature oder bug?

thanks for helping and looking into it!

cheers,
sebowim

1 Like

@Measure thank you very much - this does exactly what I want - the perspective difference is so minor that its not a drama.

Still I wonder why this is not working natively?

Best regards and thank you very much for your script!
sebowim

1 Like

As for why it’s not trivial to crop perspective views, consider this view with an array of spheres. I’ve increased the lens length to exaggerate the effect, but notice how the spheres in the corners of the viewport are distorted. This is caused by the projection of the camera onto a flat screen. If you were to crop the viewport to the red rectangle, the entire view would have to be skewed diagonally to match the scene in the original, larger viewport. This is unavoidable for any crop that doesn’t keep the center of the viewport constant.

1 Like

hmm ok I think I kind of understand what you mean - I just can’t get rid of thinking it is “just” an expansion of the viewport to the cropped side - like changing a window size by not interfering with its content.

thank you!

1 Like

This is awesome! I had a feeling this was possible :slightly_smiling_face: Rhino the best CAD. :face_holding_back_tears: