Setting scenes for Layout: ratio width / height

I’m modeling pretty simple … models. Each time i have to make a Layout presentation from the model. It’s with a template containing multiple pages and views of the model.

Because the models are of different size (and shape), we always had some work in layout to set the different viewports correct. It’s mostly a bit of zooming.

To reduce that work i made a script that:

  1. asks the user to set the viewport to a certain ratio width to height (with a bit of margin) → if it’s too wide, it asks the user to set it smaller and stops the script. After resizing the user can start the script again.
  2. all my scenes are ‘zoom extended’
  3. save the model and sent it to Layout

After that, the Layout-presentation is in 95% of the cases immediately OK.

I found out that it is important that the ratio of width/height in Sketchup viewing is circa the same as the width/height ratio in the Layout viewports.

The only thing is, asking the user to set the ratio within a certain margin is a bit a ‘pain in the you know’.
So i have the question if there is a better solution for this?

view = model.active_view
ratio = view.vpwidth / view.vpheight
if ratio > x
  UI.messabox('Set your screen smaller')
elsif ratio < y

What is x and what is y ?

I’d start with this …


That’ll put a 5% margin on the greatest axis of the view.

Then you can get the model bounds via …

bb = model.bounds

… and the screen coords of the bounding box’s corners via calls like …

coords = []
for i in 0..7
  coords << view.screen_coords(bb.corner(i))
# convert 3D point objects to xy integer arrays! { |pt| [pt.x.to_i, pt.y.to_i] } 
min_x = coords.min_by(&:x).x
min_y = coords.min_by(&:y).y
max_x = coords.max_by(&:x).x
max_y = coords.max_by(&:y).y

Now you have the 2D dimensions of the model bounds.

The viewport ratio in SketchUp doesn’t really matter in LayOut in my experience. What does matter is the vertical extent of the view. If your LayOut viewport has another ratio, then the sides of the view will either be cut off or extended, but the top and bottom will match the SketchUp view. Often the top and bottom are by far the most important anyway as the view needs to end with a reasonable amount of floor and ceiling being show, while the extent sideways doesn’t matter that much.