AutoCAD C#初学者,要学习AutoCAD .NET Developer's Guide时,自己编写了一个Polyline绘制命令。想要实现如用CAD绘制Polyline时适时显示已经绘制部分的多段线。可是这个命令只在第一次执行才能适时显示,以后再调用这个命令时只在绘制完毕时显示多段线,而不会在绘制过程中适时显示,请大家看看我的代码问题出在哪里,多谢!
- [CommandMethod("WR1")] //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[BlockTableRecord.ModelSpace], 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
|