Zoom to part

Hi @Mahdiyar I found your script in this post.

I added a rotation input so the up vector is perpendicular to the longest edge of my surface boundary. I was wondering if a Zoom Bounding box command could be added to your C# script?

I’m currently using a separate python script for zooming. It seems to work. Before using your C# script for the view orientation, I had a faulty python python script which should have done both but it didn’t really work. Your script works fine and if it could zoom in on a part that would be super perfect!

zoom_to_part.gh (24.4 KB)

I dont know C# so well…but maybe something like this:

    var vp = RhinoDocument.Views.ActiveView.ActiveViewport;
    var vbbox = new Rhino.Geometry.BoundingBox(bbox.GetCorners());
    vp.SetCameraLocations(target, location);
    vec.Rotate(RhinoMath.ToRadians(rotation), vp.CameraDirection);
    vp.ZoomBoundingBox(vbbox);
    Rhino.ApplicationSettings.ViewSettings.ZoomExtentsParallelViewBorder = 0.72;

With a bbox input set to Type Box.

I get these two errors:

  1. Error (CS1502): Die beste Übereinstimmung für die überladene ‘Rhino.Display.RhinoViewport.ZoomBoundingBox(Rhino.Geometry.BoundingBox)’-Methode hat einige ungültige Argumente. (line 63)

  2. Error (CS1503): Argument ‘1’: Konvertierung von ‘Rhino.Geometry.Box’ in ‘Rhino.Geometry.BoundingBox’ nicht möglich. (line 63)

I don’t understand what data type the box needs to be. In python the box is input as a list of 8 points.

Strange, I dont get an error. Maybe try this:
zoom_to_part_v2.gh (20.1 KB)

Here is a Pythonic version:
zoom_to_part_v3.gh (16.0 KB)

1 Like

Ah got it, I didn’t include the line for the vbbox further up in the code

This works:

    var vp = RhinoDocument.Views.ActiveView.ActiveViewport;
    vp.SetCameraLocations(target, location);
    vec.Rotate(RhinoMath.ToRadians(rotation), vp.CameraDirection);
    vp.CameraUp = vec;
    var vbbox = new Rhino.Geometry.BoundingBox(bbox.GetCorners());
    vp.ZoomBoundingBox(vbbox);

Thanks for your help @Adam_M

1 Like