Cad.net Modifying viewport proportions

Source: Internet
Author: User

[Commandmethod ("Changezoom")]

static public void Commandchangeviewportzoom ()

{

Access database and editor

Database db = Application.documentmanager.

Mdiactivedocument.database;

Editor ed = Application.documentmanager.

Mdiactivedocument.editor;

using (Transaction TR = db.

Transactionmanager.starttransaction ())

{

LayoutManager layoutmgr = layoutmanager.current;

Layout Layoutobj;

Dbdictionary layoutdict;

Ed. Writemessage ("number of Layouts = {0}\n",

Layoutmgr.layoutcount);

Ed. Writemessage ("Current Layout = {0}\n",

Layoutmgr.currentlayout);

Point3D x_min = db. Extmin;

Point3D X_max = db. Extmax;

using (layoutdict = tr. GetObject (db. Layoutdictionaryid,

Openmode.forread) as Dbdictionary)

{

foreach (DictionaryEntry layoutentry in layoutdict)

{

using (layoutobj = tr. GetObject (

(ObjectId) (Layoutentry.value),

Openmode.forread) as Layout)

{

Set the currentlayout to the layout

If it is not modelspace

if (layoutobj.layoutname! = "Model")

Layoutmgr.currentlayout = Layoutobj.layoutname;

Ed. Writemessage ("Layout Name = {0}\n",

Layoutobj.layoutname);

Blocktablerecord r = tr. GetObject (

Layoutobj.blocktablerecordid,

Openmode.forread) as Blocktablerecord;

foreach (ObjectId obj in R)

{

DBObject dbobj = tr. GetObject (obj, openmode.forread);

Viewport VP = dbobj as Viewport;

if (VP! = null)

{

Ed. Writemessage ("\nnumber of Viewport = {0}",

Vp. number);

Get the screen aspect ratio to calculate

The height and width

Double Mscrratio;

Width/height

Mscrratio = (VP. WIDTH/VP. Height);

Point3D mmaxext = db. Extmax;

Point3D mminext = db. Extmin;

Extents3d mextents = new Extents3d ();

Mextents.set (Mminext, Mmaxext);

Prepare Matrix for DCS to WCS transformation

Matrix3D Matwcs2dcs;

Matwcs2dcs = Matrix3d.planetoworld (VP. Viewdirection);

Matwcs2dcs = Matrix3d.displacement (

Vp. Viewtarget-point3d.origin)

* MATWCS2DCS;

Matwcs2dcs = Matrix3d.rotation (

-VP. Twistangle, VP. Viewdirection,

Vp. Viewtarget) * MATWCS2DCS;

Matwcs2dcs = Matwcs2dcs.inverse ();

Tranform the extents to the DCS

Defined by the Viewdir

Mextents.transformby (Matwcs2dcs);

Width of the extents in current view

Double mwidth;

Mwidth = (mextents.maxpoint.x-mextents.minpoint.x);

Height of the extents in current view

Double mheight;

Mheight = (MEXTENTS.MAXPOINT.Y-MEXTENTS.MINPOINT.Y);

Get the View center point

POINT2D mcentpt = new POINT2D (

((Mextents.maxpoint.x + mextents.minpoint.x) * 0.5),

((Mextents.maxpoint.y + mextents.minpoint.y) * 0.5));

Check if the width ' fits ' in current window,

If not then get the new height as

Per the viewports aspect ratio

if (Mwidth > (mheight * mscrratio))

Mheight = Mwidth/mscrratio;

Set the viewport parameters

if (VP. Number = = 2)

{

Vp. Upgradeopen ();

Set the View height-adjusted by 1%

Vp. Viewheight = Mheight * 1.01;

Set the View Center

Vp. Viewcenter = MCENTPT;

Vp. Visible = true;

Vp. on = true;

Vp. Updatedisplay ();

Ed. Switchtomodelspace ();

Application.setsystemvariable ("Cvport", VP. number);

}

if (VP. Number = = 3)

{

Vp. Upgradeopen ();

Vp. Viewheight = mheight * 1.25;

Set the View Center

Vp. Viewcenter = MCENTPT;

Vp. Visible = true;

Vp. on = true;

Vp. Updatedisplay ();

Ed. Switchtomodelspace ();

Application.setsystemvariable ("Cvport", VP. number);

}

}

}

}

}

}

Tr.commit ();

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.