乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 43|回复: 2

在屏幕上绘制矩形

[复制链接]

1

主题

3

帖子

1

银币

初来乍到

Rank: 1

铜币
7
发表于 2016-1-12 04:29:06 | 显示全部楼层 |阅读模式

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

15

主题

687

帖子

169

银币

中流砥柱

Rank: 25

铜币
582
发表于 2016-1-12 06:58:20 | 显示全部楼层
您好,
您可能可以从GeometryExtension库中获得一些灵感。
回复

使用道具 举报

1

主题

3

帖子

1

银币

初来乍到

Rank: 1

铜币
7
发表于 2016-1-12 09:03:21 | 显示全部楼层
哇。。。
这真是太好了...非常感谢这个伟大的链接,一个伟大的工作!
我没有找到这个;我谷歌DCStoWCS而不是DCS2WCS...
这是工作代码
  1.         public void RectangleAtScreen()
  2.         {
  3.             Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
  4.             Point3d LL, UR;
  5.             if (!GetRectangle(out LL, out UR))
  6.                 ed.WriteMessage("*Cancel*");
  7.             else
  8.             {
  9.                 Document acDoc = Application.DocumentManager.MdiActiveDocument;
  10.                 Database acCurDb = acDoc.Database;
  11.                 // Start a transaction
  12.                 using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
  13.                 {
  14.                     BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
  15.                     BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
  16.                     Matrix3d ToWCS = ed.UCS2WCS();
  17.                     Matrix3d ToDCS = ed.WCS2DCS();
  18.                     LL = LL.TransformBy(ToWCS).TransformBy(ToDCS);
  19.                     UR = UR.TransformBy(ToWCS).TransformBy(ToDCS);
  20.                     ToWCS = ed.DCS2WCS();
  21.                     using (Polyline pl = new Polyline())
  22.                     {
  23.                         pl.SetDatabaseDefaults();
  24.                         pl.ColorIndex = 2;
  25.                         pl.Closed = true;
  26.                         var LL2d = LL.Convert2d();
  27.                         var UR2d = UR.Convert2d();
  28.                         pl.AddVertexAt(0, LL2d, 0, 0, 0);
  29.                         pl.AddVertexAt(1, new Point2d(UR2d.X, LL2d.Y), 0, 0, 0);
  30.                         pl.AddVertexAt(2, UR2d, 0, 0, 0);
  31.                         pl.AddVertexAt(3, new Point2d(LL2d.X, UR2d.Y), 0, 0, 0);
  32.                         pl.TransformBy(ToWCS);
  33.                         acBlkTblRec.AppendEntity(pl);
  34.                         acTrans.AddNewlyCreatedDBObject(pl, true);
  35.                         acTrans.Commit();
  36.                     }
  37.                 }
  38.             }
  39.         }
  40.         private static bool GetRectangle(out Point3d first, out Point3d second)
  41.         {
  42.             Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
  43.             first = default(Point3d);
  44.             second = default(Point3d);
  45.             try
  46.             {
  47.                 PromptPointResult ppt = ed.GetPoint("Pick Lower-Left Corner");
  48.                 if (ppt.Status == PromptStatus.OK)
  49.                 {
  50.                     first = ppt.Value;
  51.                     var pco = new PromptCornerOptions("Pick Upper-Right Corner", first);
  52.                     pco.UseDashedLine = true;
  53.                     ppt = ed.GetCorner(pco);
  54.                     if (ppt.Status == PromptStatus.OK)
  55.                     {
  56.                         second = ppt.Value;
  57.                         return true;
  58.                     }
  59.                 }
  60.             }
  61.             catch (System.Exception ex)
  62.             {
  63.                 ed.WriteMessage(ex.ToString());
  64.             }
  65.             return false;
  66.         }

问候reltro
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-2-4 21:56 , Processed in 0.197235 second(s), 69 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表