明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1437|回复: 1

即时显示绘制多义线

[复制链接]
发表于 2010-2-25 09:14:00 | 显示全部楼层 |阅读模式
本帖最后由 作者 于 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

发表于 2010-2-25 18:59:00 | 显示全部楼层
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 20:53 , Processed in 0.165241 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表