Prod.: Engine, ver.: 6, ID: 60001591, HowTo : Create a viewport that replicates the 3D view shown in the model view

HowTo : Create a viewport that replicates the 3D view shown in the model view

Article60001591
TypeHowTo
ProductEngine
Version6
Date Added1/4/2012
Submitted byBruce Jacobs
Keywords

Subject

Create a viewport that replicates the 3D view shown in the model view

Summary

I have a situation where I would like to create a Viewport within a layout for a rotated 3D image. I’d like the new Viewport to show exactly what’s in the model view, with the same rotation, target point, extent, etc. Do you have some code in one of the sample applications or elsewhere that will accomplish what I’m looking for? That is to create a viewport that replicates the 3d view shown in the model view.

Solution

You can use a vdView object for this, which will copy all the “view” properties of a layout or model to another layout/vieport etc.

See the code below :
private void button3_Click(object sender, EventArgs e)
{
    vdDocument doc = vdFramedControl1.BaseControl.ActiveDocument; 
    vdLayout lay = new vdLayout(doc, "BBB");
    doc.LayOuts.AddItem(lay);
    vdViewport vp = new vdViewport(); vp.SetUnRegisterDocument(doc); 
    vp.setDocumentDefaults();
    vp.Height = doc.Model.ViewSize / doc.Model.PixelSize;
    vp.Width = vdFramedControl1.BaseControl.Width;
    vp.Center = new gPoint(vp.Width/2.0, vp.Height / 2.0d);
 
    vdView viewTMP = new vdView(doc, "mYvIEW1");
    viewTMP.SetFromLayout(doc.Model);
    vp.SetFromView(viewTMP);// viewTMP is not necessary to be 
         //  added to the document in such occasions 
 
    // or by hard code, without using the vdView object like :
    //vp.World2ViewMatrix = new Matrix(doc.Model.World2ViewMatrix);
    //vp.ViewCenter = new gPoint(doc.Model.ViewCenter);
    //vp.ViewSize = doc.Model.ViewSize;
    //vp.RenderMode = doc.Model.RenderMode;
    // set also PerspectiveMod,LensAngle, FocalLength etc if you use them
    
    lay.Entities.AddItem(vp);
    if (vp.Height < vp.Width) lay.Printer.LandScape = true;
    lay.Printer.PrintExtents(); lay.Printer.PrintScaleToFit(); 
    lay.Printer.Update(); lay.Update();
    doc.ActiveLayOut = lay;
    doc.CommandAction.Zoom("E", 0, 0);
}