Zoom to object with no gaps around it (Just like AutoCAD does)

Hi everyone!

Just trying to zoom-to-object with no gaps, just like AutoCAD does. Rhino has zoom to object but it leaves a gap around the object.

Any help will he highly appreciated!

Hi @Fernando_González-Ca ,

#farouk.serragedine@gmail.com for custom made solutions - Rhinoceros Plugins
import Rhino
import rhinoscriptsyntax as rs

def ZoomToTightBoundingBox():
    object_ids = rs.SelectedObjects()
    if not object_ids:
        object_ids = rs.GetObjects("Select objects to zoom tightly", preselect=True)
        if not object_ids: return
    # Get the bounding box of the selected objects
    bounding_box = rs.BoundingBox(object_ids)
    if not bounding_box: return
    box = Rhino.Geometry.BoundingBox(bounding_box)
    # Get the active view
    view = rs.CurrentView()
    if not view: return
    rhino_view = Rhino.RhinoDoc.ActiveDoc.Views.Find(view, False)
    # Calculate the tight zoom factor
    rhino_view.ActiveViewport.ZoomBoundingBox(box)
    rhino_view.Redraw()
if __name__ == "__main__":
    ZoomToTightBoundingBox()

Select an object and then run the script.
It will work precisely as autocad does and leave no gaps in the zoom as requested.

Hope this helps,
Farouk

1 Like

Thanks for such a quick reply! That sounds excactly like what I need. However I get this error when loading the script:

It’s a python script, not a rhinoscript.
Anyway I compiled an Rhi for you I guess It’ll be easier.
Just execute the rhi, then type in the rhino console “zoomnogap”
zoomnogap.rhi (4.1 KB)

Farouk

Hi Fernando -

You can set the advanced option Rhino.Options.View.ZoomExtentsParallelViewBorder to 1 to achieve this.
-wim

1 Like

Thanks a lot everyone!! amazing to get such quick responses!! Wim’s solution worked wonders!!

“You can set the advanced option Rhino.Options.View.ZoomExtentsParallelViewBorder to 1 to achieve this.”

Fernando