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(); } }
标签:Matrix3d,objectid,WCS2DCS,实体,tr,zoom,ext,ent,view From: https://www.cnblogs.com/swtool/p/17437830.html