autocad.net(c#)获取autocad模型空间窗口大小

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 //by 鸟哥 qq1833183060
//qq群 720924083
//2020-11-09
/// <summary>
/// 获取autocad模型空间窗口大小
/// 参考 https://adndevblog.typepad.com/autocad/2012/04/getting-the-extents-of-autocad-model-window.html
/// </summary>
[CommandMethod("ScreenExtents")]
public void ScreenExtents()
{
Document doc = Application.DocumentManager.MdiActiveDocument;

Database db = doc.Database;

Editor ed = doc.Editor;
Point2d screenSize = (Point2d)Application.GetSystemVariable("SCREENSIZE");
System.Drawing.Point upperLeft = new System.Drawing.Point(0, 0);
System.Drawing.Point lowerRight = new System.Drawing.Point((int)screenSize.X,(int)screenSize.Y);
Point3d upperLeftWorld = ed.PointToWorld(upperLeft, 0);

Point3d lowerRightWorld = ed.PointToWorld(lowerRight, 0);
using (Transaction Tx = db.TransactionManager.StartTransaction())
{
//Draws a line to visualize result...

Line line = new Line(upperLeftWorld, lowerRightWorld);

BlockTableRecord btr = Tx.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
btr.AppendEntity(line);

Tx.AddNewlyCreatedDBObject(line, true);
Tx.Commit();
}
}