Positioning detail.viewport (top view) to a given point co-ordinate

Multiple detail view is done and working fine. Now I am not sure how to set position of the detail view in the rhino view port( top view)
I have several drawing details. I have to set position of each detail view for each drawing .

doc.PageUnitSystem = Rhino.UnitSystem.Millimeters;
var page_views = doc.Views.GetPageViews();
int page_number = (page_views == null) ? 1 : page_views.Length + 1;
var pageview = doc.Views.AddPageView(string.Format(“A0_{0}”, page_number), 1189, 841);

            Rhino.Geometry.Point2d top_left = new Rhino.Geometry.Point2d(500, 821);
            Rhino.Geometry.Point2d bottom_right = new Rhino.Geometry.Point2d(1169, 500);
            var detail = pageview.AddDetailView("ModelView", top_left, bottom_right, Rhino.Display.DefinedViewportProjection.Top);
            if (detail != null)
            {
                pageview.SetActiveDetail(detail.Id);
                detail.Viewport.ZoomExtents();
                detail.DetailGeometry.IsProjectionLocked = true;
                detail.DetailGeometry.SetScale(1, doc.ModelUnitSystem, 10, doc.PageUnitSystem);
                // Commit changes tells the document to replace the document's detail object
                // with the modified one that we just adjusted
                detail.CommitChanges();
            }
            pageview.SetPageAsActive();
            doc.Views.ActiveView = pageview;
            doc.Views.Redraw();

return Rhino.Commands.Result.Success;

If I understand correctly, you’ve created a layout and add one one or more details to the layout. Now you want to orient each layout’s viewport. Is this correct?

If so, then the DetailViewObject object has a viewport that you can obtain by calling DetailViewObject.RhinoViewport. Once, you have the viewport, you can manipulate it just as you would a standard viewport.

1 Like

Dear Dale,
I wanted you reply here… I send you Message, so you will see my post here :smile:
Thanks for the reply.

Well I think I am not able to identify which one is for moving and adjusting the position.
If you see the faulty code below. You will see I tried several things. All line s are not correct, but it will give you clue that I am not sure which method I should use to move it to the right world co-ordinate.
For example if I move the origin of my viewport to Point3d(120.0, 140.0, 0.0)
then what should I write.

I am confused how to do it for viewport

           // Point3d min=new Point3d(20,20,0);
           // Point3d max=new Point3d(400,400,0);
            //BoundingBox bbox = new BoundingBox(min, max);
            
            
            Rhino.Geometry.Point2d top_left1 = new Rhino.Geometry.Point2d(20,400);
            Rhino.Geometry.Point2d bottom_right1 = new Rhino.Geometry.Point2d( 400,20);
            var detail1 = pageview.AddDetailView("ModelView1", top_left1, bottom_right1, Rhino.Display.DefinedViewportProjection.Top);
            
        
        
            if (detail1 != null)
            {
                pageview.SetActiveDetail(detail1.Id);
                //detail1.Viewport.ZoomExtents();
                //Point3d ptl = new Point3d(100, 150, 0);
               // Vector3d vtl = new Vector3d(0, 0, 1);
              //  Vector3d vtx = new Vector3d(1, 0, 0);
               // Vector3d vty = new Vector3d(0, 1, 0);
                
               // Plane plane_r = new Plane(ptl, vtl);
              //  detail1.Viewport.WorldToClient(ptl);
              //  detail1.Viewport.SetToPlanView(ptl, vtx, vty, true);
                //detail1.Viewport.ZoomBoundingBox(bbox);
                //detail1.Viewport.
                //Point2d ptu = new Point2d(50, 50);
               // detail1.Viewport.ClientToScreen(

                
                 
                
                
                //Point3d pt = new Point3d(233.03, 110.70, 0.0);
                //Vector3d dir = pt - Point3d.Origin;
                //Transform xform = Transform.Translation(dir);
                //detail1.Viewport.
               
                //detail1.Viewport.GetNearRect()
                // detail1.Viewport.Size;
                BoundingBox bboxs= detail1.DetailGeometry.GetBoundingBox(plane_r);
                detail1.Viewport.ZoomBoundingBox(bboxs);
                
                
                
                
                detail1.DetailGeometry.IsProjectionLocked = true;
                detail1.DetailGeometry.SetScale(1, doc.ModelUnitSystem, 10, doc.PageUnitSystem);
                
                
                // Commit changes tells the document to replace the document's detail object
                // with the modified one that we just adjusted
                detail1.CommitChanges();

DetailViewObject.RhinoViewport. then which method? Tell me the method please… Nothing work so far.

you just need to tell me which method to move the viewport origin to a given point Co-ordinate for example Point3d(1700.0,1400.0,00)
that was my exact question.

I tried all many things nothing move the view port to the given point of model view.
For example if I have a drawing started at that 3d point, so I need to move my viewport there.

If you were using C++ and wanted to pan a viewport, you’d call CRhinoViewport::MouseLateralDolly. But I don’t see this exposed in RhinoCommon yet. But using RhinoViewport.SetCameraTarget should work OK for panning as long as the viewport is in a parallel projection.

1 Like

Thanks Dale for the reply…But not really sure, why you are not understanding my question. Am I
so bad in expressing my question? :cry:
In one word, I need to move the detail-viewport origin to a given point in model-viewport

detail view does not move at all the way you told me above, by changing camera target… it is standing as it is…
I also tried to set camera direction and camera location. But no changes , as it is.
If it would be positioned wrong , I would think it is working.
I can write c++ plugin. But want to stay in RhinoCommon, it is a big tool. and I am only stuck with this layout issue only. Other part I will be handling properly in RhinoCommon, smoothly once this layout thing is sorted out. So I want to stay with RhinoCommon. I will not need any help after I digest this layout thing at simplest version.

                 Point3d pt1 = new Point3d(1000, 1500, 0);
                  Point3d pt2 = new Point3d(1000, 1500, 200);
                Vector3d vt1 = new Vector3d(pt1);
                Vector3d vt2 = new Vector3d(pt2);
                
                Vector3d vt =vt2-vt1;
                
               

                detail1.Viewport.SetCameraDirection(vt, true);
                detail1.Viewport.SetCameraLocation(pt2, true);
                detail1.Viewport.SetCameraTarget(pt1, true);

Like I said, if you are in a Parallel-projected viewport, then all you should need to do is call Viewport.SetCameraTarget. But I think you are going to have to do more to get the correct camera location too.

Here is an example of zooming to the geometric extents in all details in a layout. Perhaps this sample you get you going in the right direction.

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  var page_view = doc.Views.ActiveView as RhinoPageView;
  if (null != page_view && page_view.PageIsActive)
  {
    foreach (var detail in page_view.GetDetailViews())
    {
      // Set the detail active
      detail.IsActive = true;
      // Zoom extents
      detail.Viewport.ZoomExtents();
      // Commit changes
      detail.CommitViewportChanges();
      // Redraw view
      page_view.Redraw();
      // Give Rhino a chance to redraw before continuing...
      RhinoApp.Wait();
    }
    // Set page view active
    page_view.SetPageAsActive();
    // Redraw view
    page_view.Redraw();
  }

  return Result.Success;
}

For multiple drawing in one 3dm file, I still think its best to add some geometry around each drawing that you can ZoomExtendsSelected

1 Like

Hi Dale, The code you wrote I did not try it, because it is clearly said, zoom extent, so it will zoom extent to everything in the drawing space for each detail view. Hope you did not mind…
It will not be able to move to specific point. But I know I can create box around my drawing and select them and zoom extent … I do not want to select them . Rather fascinated about Camera Target…

I guess your first option was more needed Camera Target
If you please write few lines how camera target works will be a great help.
I understand ZoomExtendsSelected…may work for certain cases even I can move to a given box as you mentioned in your other post, but in my case, I need to move Camera target should serve my purpose in later stage of my project and would be nice to have a code on this.

Thanks in advance :slight_smile: ZoomExtents is also useful in certain work flow but in this case.
. It will be useful for other purpose if I know Camera handling properly…

If you give this small sample on Camera Target and how it works will give me some idea .

Many thanks !

Just replace:

detail.Viewport.ZoomExtents();

with

detail.Viewport.SetCameraTarget(point, true);
1 Like

Ok:) Many thanks Dale !

The reason why my code was not working is
I was calling
detail.CommitChanges();
but to commit change to the Viewport location I should write
detail.CommitViewportChanges();

detail.CommitChanges(); should be used, when there is some changes in detail, other than viewport.

Now it is working perfect… Many thanks !
I was known I was making a small mistake or I was missing something, so I had requested for source code and yes your code solved my problem.
Many thanks again ! :smile: