[RhinoCommon] use of ViewportInfo to restore viewport

Today I was running into a problem when I wanted to save and restore viewport settings.
I can get a ViewportInfo object with all the settings from a RhinoViewport by using the constructor that takes a RhinoViewport object.
But, if my viewport has changed, I don’t see any way to restore the viewport using the previously saved ViewportInfo.

I ended up doing this in C++ where I can save ON_3dmView objects (viewport.View()) and restore the settings (viewport.SetView(saved_view)). There it works perfectly.

Is this an oversight in RhinoCommon, or did I not see how to restore a viewport from a given ViewportInfo object?

1 Like

To save and restore viewport settings in RhinoCommon, you can use RhinoDoc.NamedViews. For example:

RhinoView view = doc.Views.ActiveView;
if (null != view)
{
  int index = doc.NamedViews.Add("MyViewInfo", view.ActiveViewportID);

  // TODO...

  doc.NamedViews.Restore(index, view, false);
}

Also, if you have a ViewportInfo, you should be able to use RhinoView.ActiveViewport.SetViewProjection.

1 Like

Hi Menno,
Would you please tell me how to move a view in detail.viewport in a layout?

I mean i have several drawings to arrange in a layout. i am using rhinocommon c# dot net. I need to set
detail.viewport to the right area, where my drawings are.
i never did this in rhinocommon. mostly I busy with geometry algorithm. First time i have to arrange a drawing in rhinocommon.

If you know how to move detail-view to the right place of model view, then please let me know. it should be something to move the view and should be quite easy with right method, but i have no clue…

Best regards
Taha

If you using just Rhino commands, what would you do?

1 Like

I would just pan/zoom/move it to the right place… or zoom or dolly mouse and adjust to the right place…

But it need to be automated. Just to move the detail. viewport to the right place of model place.

Moving viewport or transforming viewport I could not find a normal transform method in RhinoCommon.

You cannot transform a viewport. But there are a number of member on RhinoViewport that will allow you to setup the view.

You mentioned that you have several drawings in your 3DM file. If these “drawing” include a title block or are bounded by some kind of border, then you could select the border and then call RhinoViewport.ZoomExtendsSelected, for example.

1 Like

I have replied to you, in my other post :smile: