求助:自己编写的绘制Polyline命令无法在第二次调用时适时显示已绘制部分.
AutoCAD C#初学者,要学习AutoCAD .NET Developer's Guide时,自己编写了一个Polyline绘制命令。想要实现如用CAD绘制Polyline时适时显示已经绘制部分的多段线。可是这个命令只在第一次执行才能适时显示,以后再调用这个命令时只在绘制完毕时显示多段线,而不会在绘制过程中适时显示,请大家看看我的代码问题出在哪里,多谢!//WR1=MPL,MyPolyline
public static void MyPolyline()
{
// Get the current document and database
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
Editor acEd = acDoc.Editor;
// Start a transaction
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Open the Block table for read
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
// Open the Block table record Model space for write
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl, OpenMode.ForWrite) as BlockTableRecord;
// Create a polyline with two segments (3 points)
Polyline acPoly = new Polyline();
acBlkTblRec.AppendEntity(acPoly);
acTrans.AddNewlyCreatedDBObject(acPoly, true);
PromptPointResult pPtRes;
PromptPointOptions pPtOpts = new PromptPointOptions("");
// Prompt for the start point
pPtOpts.Message = "\nEnter the 1st point: ";
pPtOpts.AllowArbitraryInput = true;
pPtOpts.AllowNone = true;
pPtOpts.UseDashedLine = true;
pPtRes = acDoc.Editor.GetPoint(pPtOpts);
Point2d ptVetex;
int intPtCount = 0;
while (pPtRes.Status == PromptStatus.OK)
{
ptVetex = new Point2d(pPtRes.Value.X, pPtRes.Value.Y);
acPoly.AddVertexAt(intPtCount, ptVetex, 0, 0, 0);
acEd.Regen();
intPtCount += 1;
pPtOpts.Message = "\nEnter the " + (intPtCount+1).ToString() + "th(st/nd/rd) point of the line: ";
pPtOpts.UseBasePoint = true;
pPtOpts.BasePoint = pPtRes.Value;
pPtRes = acDoc.Editor.GetPoint(pPtOpts);
}// End while
acTrans.Commit();
}// end using transaction
}// end MyPolyline
把38行
acEd.Regen();
改成
acPoly.Draw();
试试看 本帖最后由 syeanwoo 于 2011-10-18 18:52 编辑
yanglin112 发表于 2011-10-18 16:08 static/image/common/back.gif
把38行
acEd.Regen();
改成
能行了!非常感谢!请问能讲解一下原理吗?非常感谢。 syeanwoo 发表于 2011-10-18 18:50 static/image/common/back.gif
能行了!非常感谢!请问能讲解一下原理吗?非常感谢。
呵呵,我也是新手啦,我只知道acEd.Regen()是对整体DWG文件刷新,消耗会比较大,至于到底什么原因我也不大清楚啦,希望高手来解答啦! yanglin112 发表于 2011-10-19 08:59 static/image/common/back.gif
呵呵,我也是新手啦,我只知道acEd.Regen()是对整体DWG文件刷新,消耗会比较大,至于到底什么原因我也不大 ...
谢谢!我觉得Editor.Regen()方法是对屏幕上的图形重新生成并显示,应该就包含了每个实体的Draw()方法,不知道不怎么回事,总之再次感谢您!
页:
[1]