- 积分
- 30299
- 明经币
- 个
- 注册时间
- 2016-9-16
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 fangmin723 于 2024-6-11 13:45 编辑
- [CommandMethod("ScreenExtents")]
- public void ScreenExtents()
- {
- Document doc = Acap.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- var ext = Env.ScreenArea;
- var ext1 = Env.DrawingArea;
- using (Transaction Tx = db.TransactionManager.StartTransaction())
- {
- //Draws a line to visualize result...
- Line line = new Line(ext.MinPoint, ext.MaxPoint);
- Line line1 = new Line(ext1.MinPoint, ext1.MaxPoint);
- line1.ColorIndex = 1;
- BlockTableRecord btr = Tx.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
- btr.AppendEntity(line);
- btr.AppendEntity(line1);
- Tx.AddNewlyCreatedDBObject(line, true);
- Tx.AddNewlyCreatedDBObject(line1, true);
- Tx.Commit();
- }
- }
autocad.net(c#)获取autocad模型空间窗口大小_c#获取窗口大小-CSDN博客
- /// <summary>
- /// 获取绘图区域范围[左下,右上]
- /// 参考:<see href="https://adndevblog.typepad.com/AutoCAD/2012/04/getting-the-extents-of-autocad-model-window.html"/>
- /// </summary>
- public static Extents3d ScreenArea
- {
- get
- {
- var doc = Acap.DocumentManager.MdiActiveDocument;
- var ed = doc.Editor;
- var screenSize = (Point2d)Acap.GetSystemVariable("SCREENSIZE");
- var leftUpper = new System.Drawing.Point(0, 0);
- var rightLower = new System.Drawing.Point((int)screenSize.X, (int)screenSize.Y);
- var leftUpperPt = ed.PointToWorld(leftUpper, 0);
- var rightLowerPt = ed.PointToWorld(rightLower, 0);
- return new(leftUpperPt.GetMinPtTo(rightLowerPt), leftUpperPt.GetMaxPtTo(rightLowerPt));
- }
- }
- /// <summary>
- /// 获取绘图区域范围[左下,右上]
- /// 参考:<see href="http://bbs.mjtd.com/forum.php?mod=redirect&goto=findpost&ptid=171361&pid=763395&fromuid=7316343"/>
- /// </summary>
- public static Extents3d DrawingArea
- {
- get
- {
- var areaCenter = "VIEWCTR".GetVar<Point3d>();
- var areaHeight = "VIEWSIZE".GetVar<double>() * 0.5;
- var areaSize = "SCREENSIZE".GetVar<Point2d>();
- var areaVect = new Vector3d(areaSize.X / areaSize.Y * areaHeight, areaHeight, 0);
- return new(areaCenter - areaVect, areaCenter + areaVect);
- }
- }
出自:IFoxCad
- /// <summary>
- /// 获取CAD的系统变量
- /// </summary>
- /// <typeparam name="T">值的类型</typeparam>
- /// <param name="name">要获取的系统变量名称</param>
- /// <returns>返回系统变量</returns>
- public static T GetVar<T>(this string name)
- {
- if (string.IsNullOrEmpty(name)) return default;
- try { return (T)Acap.GetSystemVariable(name); }
- catch (Exception) { throw; }
- //return Acaop.GetSystemVariable(name);
- }
- /// <summary>
- /// 设置CAD的系统变量
- /// 0x01 建议先获取现有变量值和设置的是否相同,否则直接设置会发生异常<br/>
- /// 0x02 建议锁文档,否则 Psltscale 设置发生异常<br/>
- /// 发生异常的时候vs输出窗口会打印一下,但是如果不介意也没啥问题
- /// </summary>
- /// <param name="name">要设置的系统变量名称</param>
- /// <param name="value">要设置的系统变量值</param>
- /// <param name="echo">输出异常,默认true;此设置仅为打印到命令栏,无法控制vs输出</param>
- public static void SetVar(this string name, object value, bool echo = true)
- {
- if (string.IsNullOrEmpty(name)) return;
- if (value is null) return;
- try { Acap.SetSystemVariable(name, value); }
- catch (Exception) { if (echo) $"{value} 是不存在的变量!".PrintLine(); }
- }
|
评分
-
查看全部评分
|