按选择的实体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(); } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 字符编码:从基础到乱码解决