码迷,mamicode.com
首页 > Web开发 > 详细

cad.net修改视口比例

时间:2014-07-09 15:12:34      阅读:335      评论:0      收藏:0      [点我收藏+]

标签:width   art   cti   for   io   new   

[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();

  }

}

cad.net修改视口比例,布布扣,bubuko.com

cad.net修改视口比例

标签:width   art   cti   for   io   new   

原文地址:http://www.cnblogs.com/swtool/p/3832314.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!