public static void ZoomObject(this Editor editor, ObjectId objectId)
{
try
{
if (objectId.IsNull) return;
if (!objectId.IsValid) return;
if (objectId.IsErased) return;
Database db = editor.Document.Database;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
Entity entity = trans.GetObject(objectId, OpenMode.ForRead) as Entity;
if (entity == null)
{
return;
}
Extents3d extents3 = entity.GeometricExtents;
extents3.TransformBy(editor.CurrentUserCoordinateSystem.Inverse());
Point3d minp = extents3.MinPoint;
Point3d maxp = extents3.MaxPoint;
double with = maxp.X - minp.X;
double height = maxp.Y - minp.Y;
double dwith = with * 0.5;
double dheight = height * 0.5;
Point3d minp2 = new Point3d(minp.X - dwith, minp.Y - dheight, 0);
Point3d maxp2 = new Point3d(maxp.X + dwith, maxp.Y + dheight, 0);
//缩放
editor.ZoomWindow(minp2, maxp2);
trans.Commit();
editor.SetImpliedSelection(new ObjectId[] { entity.ObjectId });
entity.ObjectId.SetVisible(false);
Thread.Sleep(100);
entity.ObjectId.SetVisible(true);
Autodesk.AutoCAD.ApplicationServices.Application.UpdateScreen();
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.UpdateScreen();
}
}
catch
{
}
}
缩放并选中Entity,为了不显得Entity太大,缩放范围为Entity的2倍
于 2020-04-01 09:27:12 首次发布