Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
use this code.It work well for some file.But zoom window is not correct when zoomwin in "test.dwg"(see the attachment). My AutoCAD version is 2019.
public static void ZoomWindow(this Editor ed, Point3d pt1, Point3d pt2)
{
using (ViewTableRecord view = ed.GetCurrentView())
{
view.Width = pt1.X - pt1.X;
view.Height = pt2.Y - pt2.Y;
view.CenterPoint = new Point2d(pt1.X + (view.Width / 2),
pt1.Y + (view.Height / 2));
ed.SetCurrentView(view);
}
}
[CommandMethod("TestZoomWin", CommandFlags.UsePickSet | CommandFlags.Redraw)]
public static void OutSelAtrs()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = doc.Editor;
TypedValue[] values = new TypedValue[]
{
new TypedValue((int)DxfCode.Start, "Insert")
};
SelectionFilter filter = new SelectionFilter(values);
PromptSelectionResult ents;
if (ed.SelectImplied().Status == PromptStatus.OK && ed.SelectImplied().Value.Count > 0)
ents = ed.GetSelection(filter);
else
{
PromptSelectionOptions pso = new PromptSelectionOptions { MessageForAdding = "Please Select a Block" };
ents = ed.GetSelection(pso, filter);
if (ents.Status == PromptStatus.Cancel)
{
return;
}
else if (ents.Status != PromptStatus.OK)
{
return;
}
}
SelectionSet allselect = ents.Value;
using (Transaction trans =
doc.Database.TransactionManager.StartTransaction())
{
foreach (ObjectId id in allselect.GetObjectIds())
{
BlockReference brf = (BlockReference)trans.GetObject(id, OpenMode.ForRead);
if (brf != null)
{
Extents3d ext = brf.GeometryExtentsBestFit();
Point3d p1 = ext.MinPoint;// - brf.BlockTransform.Translation;
Point3d p2 = ext.MaxPoint;// - brf.BlockTransform.Translation;
ed.ZoomWindow(p1, p2);
}
}
trans.Commit();
}
}
Solved! Go to Solution.