欢迎加我的QQ群:193522571,一起来讨论、交流!

按选择的实体objectid来zoom时,发现一个很特别的实体dbtext

dbtext取得其GeometricExtents时,发现ext特别大,暂时不知道什么原因,所以在程序中把文字去掉了。

这一个东西测试了很长时间。

复制代码
  public static void ZoomObjects(this Editor ed, ObjectIdCollection idCol)
  {
    Document doc = AcadApp.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    using (Transaction tr = db.TransactionManager.StartTransaction())
    using (ViewTableRecord view = ed.GetCurrentView())
    {
      Matrix3d WCS2DCS = Matrix3d.PlaneToWorld(view.ViewDirection);
      WCS2DCS = Matrix3d.Displacement(view.Target - Point3d.Origin) * WCS2DCS;
      WCS2DCS = Matrix3d.Rotation(-view.ViewTwist, view.ViewDirection, view.Target) * WCS2DCS;
      WCS2DCS = WCS2DCS.Inverse();
      Entity ent = (Entity)tr.GetObject(idCol[0], OpenMode.ForRead);
      Extents3d ext = ent.GeometricExtents;
      ext.TransformBy(WCS2DCS);
      for (int i = 1; i < idCol.Count; i++)
      {
        ent = (Entity)tr.GetObject(idCol[i], OpenMode.ForRead);
        if(ent is DBText)
        {
          continue;
        }
        Extents3d tmp = ent.GeometricExtents;
        tmp.TransformBy(WCS2DCS);
        ext.AddExtents(tmp);
      }
      double ratio = view.Width / view.Height;
      double width = ext.MaxPoint.X - ext.MinPoint.X;
      double height = ext.MaxPoint.Y - ext.MinPoint.Y;
      if (width > (height * ratio))
        height = width / ratio;
      Point2d center =
          new Point2d((ext.MaxPoint.X + ext.MinPoint.X) / 2.0, (ext.MaxPoint.Y + ext.MinPoint.Y) / 2.0);
      view.Height = height;
      view.Width = width;
      view.CenterPoint = center;
      ed.SetCurrentView(view);
      tr.TransactionManager.QueueForGraphicsFlush();
      ed.Regen();
      tr.Commit();
    }
  }
复制代码

 

posted @   swtool  阅读(51)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 字符编码:从基础到乱码解决
欢迎加我的QQ群:193522571,一起来讨论、交流!
点击右上角即可分享
微信分享提示