乐筑天下

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

求助:自己编写的绘制Polyline命令无法在第二次调用时适时显示已绘制部分.

[复制链接]

1

主题

5

帖子

1

银币

初来乍到

Rank: 1

铜币
9
发表于 2011-10-18 15:03:00 | 显示全部楼层 |阅读模式
C#初学者,要学习AutoCAD .NET Developer's Guide时,自己编写了一个Polyline绘制命令。想要实现如用CAD绘制Polyline时适时显示已经绘制部分的多段线。可是这个命令只在第一次执行才能适时显示,以后再调用这个命令时只在绘制完毕时显示多段线,而不会在绘制过程中适时显示,请大家看看我的代码问题出在哪里,多谢!
  1. [CommandMethod("WR1")] //WR1=MPL,MyPolyline
  2.         public static void MyPolyline()
  3.         {
  4.             // Get the current document and database
  5.             Document acDoc = Application.DocumentManager.MdiActiveDocument;
  6.             Database acCurDb = acDoc.Database;
  7.             Editor acEd = acDoc.Editor;
  8.             // Start a transaction
  9.             using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
  10.             {
  11.                 // Open the Block table for read
  12.                 BlockTable acBlkTbl;
  13.                 acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
  14.                 // Open the Block table record Model space for write
  15.                 BlockTableRecord acBlkTblRec;
  16.                 acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
  17.                 // Create a polyline with two segments (3 points)
  18.                 Polyline acPoly = new Polyline();
  19.                 acBlkTblRec.AppendEntity(acPoly);
  20.                 acTrans.AddNewlyCreatedDBObject(acPoly, true);
  21.                 PromptPointResult pPtRes;
  22.                 PromptPointOptions pPtOpts = new PromptPointOptions("");
  23.                 // Prompt for the start point
  24.                 pPtOpts.Message = "\nEnter the 1st point: ";
  25.                 pPtOpts.AllowArbitraryInput = true;
  26.                 pPtOpts.AllowNone = true;
  27.                 pPtOpts.UseDashedLine = true;
  28.                 pPtRes = acDoc.Editor.GetPoint(pPtOpts);
  29.                 Point2d ptVetex;
  30.                 int intPtCount = 0;
  31.                 while (pPtRes.Status == PromptStatus.OK)
  32.                 {
  33.                     ptVetex = new Point2d(pPtRes.Value.X, pPtRes.Value.Y);
  34.                     acPoly.AddVertexAt(intPtCount, ptVetex, 0, 0, 0);
  35.                     acEd.Regen();
  36.                     intPtCount += 1;
  37.                     pPtOpts.Message = "\nEnter the " + (intPtCount+1).ToString() + "th(st/nd/rd) point of the line: ";
  38.                     pPtOpts.UseBasePoint = true;
  39.                     pPtOpts.BasePoint = pPtRes.Value;
  40.                     pPtRes = acDoc.Editor.GetPoint(pPtOpts);
  41.                 }// End while
  42.                 acTrans.Commit();               
  43.             }// end using transaction
  44.         }// end MyPolyline
回复

使用道具 举报

0

主题

23

帖子

2

银币

初来乍到

Rank: 1

铜币
23
发表于 2011-10-18 16:08:00 | 显示全部楼层
把38行
acEd.Regen();
改成
acPoly.Draw();
试试看
回复

使用道具 举报

1

主题

5

帖子

1

银币

初来乍到

Rank: 1

铜币
9
发表于 2011-10-18 18:50:00 | 显示全部楼层

能行了!非常感谢!请问能讲解一下原理吗?非常感谢。
回复

使用道具 举报

0

主题

23

帖子

2

银币

初来乍到

Rank: 1

铜币
23
发表于 2011-10-19 08:59:00 | 显示全部楼层

呵呵,我也是新手啦,我只知道acEd.Regen()是对整体DWG文件刷新,消耗会比较大,至于到底什么原因我也不大清楚啦,希望高手来解答啦!
回复

使用道具 举报

1

主题

5

帖子

1

银币

初来乍到

Rank: 1

铜币
9
发表于 2011-10-19 11:33:00 | 显示全部楼层

谢谢!我觉得Editor.Regen()方法是对屏幕上的图形重新生成并显示,应该就包含了每个实体的Draw()方法,不知道不怎么回事,总之再次感谢您!
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-15 17:22 , Processed in 0.816865 second(s), 63 queries .

© 2020-2025 乐筑天下

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