本帖最后由 作者 于 2010-2-25 15:09:52 编辑
我用.NET写绘制多义线的过程,但是用AddVertexAt方法添加定点后,不能即使显示刚才所添加的多义线段,而是在 acBlkTblRec.AppendEntity(acPoly) acTrans.AddNewlyCreatedDBObject(acPoly, True) 后一次显示出来,不知道设置多义线或者别的什么属性获得即时图形?代码如下 <CommandMethod("AddLightweightPolyline")> _ Public Sub AddLightweightPolyline() '' Get the current document and database Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim acCurDb As Database = acDoc.Database Dim ed As Editor = acDoc.Editor '' Start a transaction Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() '' Open the Block table for read Dim acBlkTbl As BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) '' Open the Block table record Model space for write Dim acBlkTblRec As BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _ OpenMode.ForWrite) '' Create a polyline with two segments (3 points) Dim acPoly As Polyline = New Polyline() acPoly.SetDatabaseDefaults() ' acPoly. Dim i As Integer = 0 Dim PointPrompt As PromptPointOptions = New PromptPointOptions("") PointPrompt.Message = vbLf & "选择起点:" PointPrompt.AppendKeywordsToMessage = False PointPrompt.AllowNone = False PointPrompt.UseDashedLine = True '设置橡皮筋的线型为虚线 Dim P3ddResult As PromptPointResult Do P3ddResult = ed.GetPoint(PointPrompt) '中断结束画线 If P3ddResult.Status = PromptStatus.Cancel Or P3ddResult.StringResult = "e" Then Exit Do End If If P3ddResult.StringResult = "c" Or P3ddResult.StringResult = "C" Then acPoly.Closed = True'设置多义线为闭合 Exit Do End If If P3ddResult.StringResult = "U" Or P3ddResult.StringResult = "u" Then '没写出来,那位大大能帮忙些下Undo部分啊,呵呵 End If acPoly.AddVertexAt(i, New Point2d(P3ddResult.Value.X, P3ddResult.Value.Y), 0, 0, 0) '添加多义线顶点,想在添加完这个定点后即时绘制线,如何做到?难道要另外绘制一条线段,然后在选择下个点的时候删除? ed.Regen() If i = 0 Then PointPrompt.Message = vbLf & "下一点或[\结束(E)\撤销(U)" PointPrompt.Keywords.Add("U") PointPrompt.Keywords.Add("u") PointPrompt.Keywords.Add("e") PointPrompt.Keywords.Default = "e" End If If i = 1 And PointPrompt.Keywords.Count = 3 Then PointPrompt.Message = vbLf & "下一点或[结束(E)\闭合(C)\撤销(U)]:" PointPrompt.Keywords.Add("c") PointPrompt.Keywords.Add("C") End If
i = i + 1 PointPrompt.BasePoint = P3ddResult.Value PointPrompt.UseBasePoint = True Loop '' Add the new object to the block table record and the transaction acBlkTblRec.AppendEntity(acPoly) acTrans.AddNewlyCreatedDBObject(acPoly, True)
'到这里才一次显示完所绘制的线好郁闷 '' Save the new object to the database acTrans.Commit() End Using End Sub |