zoukankan      html  css  js  c++  java
  • cad.net修改视口比例

    [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} ",

          layoutMgr.LayoutCount);

        ed.WriteMessage("Current Layout = {0} ",

          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} ",

                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(" number 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();

      }

    }

  • 相关阅读:
    deque-size
    deque-size
    deque-resize
    Android4.4——SurfaceFlinger启动
    关于linux signal 6 (SIGABRT)
    (OK) 编译ANDROID
    compile android: depmod: ERROR: Found 2 modules in dependency cycles!
    Fedora 25正式发布:工作站版默认启用Wayland显示服务器
    running ANDROID
    (3/4 OK) 在VirtualBox中运行 cm-13-kiwi (华为 荣耀 5X)
  • 原文地址:https://www.cnblogs.com/swtool/p/3832314.html
Copyright © 2011-2022 走看看