明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 709|回复: 1

[图元] 选取对象,wblock 后设定viewtablerecord居中显示

[复制链接]
发表于 2021-4-30 00:36 | 显示全部楼层 |阅读模式
本帖最后由 qq1254582201 于 2021-6-10 15:06 编辑
  1. public static class Extension
  2.     {
  3.         public static void ZoomExtents(this Database db)
  4.         {
  5.             if (db == null)
  6.                 throw new ArgumentNullException("db");

  7.             if (db.TileMode)
  8.                 acedVports2VportTableRecords();
  9.             else
  10.                 db.TileMode = true;
  11.             db.UpdateExt(false);
  12.             using (var tr = db.TransactionManager.StartOpenCloseTransaction())
  13.             {
  14.                 var view = (ViewportTableRecord)tr.GetObject(db.CurrentViewportTableRecordId, OpenMode.ForWrite);
  15.                 var ratio = view.Width / view.Height;
  16.                 var ext = new Extents3d(db.Extmin, db.Extmax);
  17.                 ext.TransformBy(view.WorldToEye());
  18.                 var lg = ext.MaxPoint.X - ext.MinPoint.X;
  19.                 var ht = ext.MaxPoint.Y - ext.MinPoint.Y;
  20.                 if (lg / ht < ratio)
  21.                 {
  22.                     view.Height = ht;
  23.                     view.Width = ht * ratio;
  24.                 }
  25.                 else
  26.                 {
  27.                     view.Height = lg / ratio;
  28.                     view.Width = lg;
  29.                 }
  30.                 view.CenterPoint = new Point2d(
  31.                     (ext.MaxPoint.X + ext.MinPoint.X) / 2.0,
  32.                     (ext.MaxPoint.Y + ext.MinPoint.Y) / 2.0);
  33.                 tr.Commit();
  34.             }

  35.         }

  36.         public static Matrix3d WorldToEye(this AbstractViewTableRecord view)
  37.         {
  38.             if (view == null)
  39.                 throw new ArgumentNullException("view");
  40.             return
  41.                 Matrix3d.WorldToPlane(view.ViewDirection) *
  42.                 Matrix3d.Displacement(view.Target.GetAsVector().Negate()) *
  43.                 Matrix3d.Rotation(view.ViewTwist, view.ViewDirection, view.Target);
  44.         }

  45.         
  46.     }

发表于 2021-4-30 09:04 | 显示全部楼层
楼主,这是可以做块预览那种吗
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-28 02:22 , Processed in 0.259959 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表