乐筑天下

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

[求助]关于如何交互绘制ployline的问题

[复制链接]

11

主题

39

帖子

8

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
83
发表于 2003-11-17 11:04:00 | 显示全部楼层 |阅读模式
请问各位,如何通过getpoint命令来绘制polyline,下面是我绘制line的程序,想同样实现绘制ployline,但无法实现,请高手指点。
Sub sdl()
Dim entry As AcadLineType
    Dim found As Boolean
    found = False
    For Each entry In ThisDrawing.Linetypes
        If StrComp(entry.Name, "acad_iso05w100", 1) = 0 Then
            found = True
            Exit For
        End If
    Next
    If Not (found) Then ThisDrawing.Linetypes.Load "acad_iso05w100", "acadiso.lin"
Dim pt1 As Variant
Dim pt2 As Variant
Dim line3 As AcadLine
pt1 = ThisDrawing.Utility.GetPoint(, "起点")
10:
On Error GoTo 20
pt2 = ThisDrawing.Utility.GetPoint(pt1, "下一点")
Set line3 = ThisDrawing.ModelSpace.AddLine(pt1, pt2)
Dim lcx As AcadLayer
Set lcx = ThisDrawing.Layers.add("虚线层")
lcx.Color = acCyan
lcx.linetype = "acad_iso05w100"
line3.Layer = "虚线层"
'line3.linetype = "acad_iso04w100"
pt1 = pt2
GoTo 10
20: Exit Sub
End Sub
回复

使用道具 举报

28

主题

117

帖子

4

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
229
发表于 2003-11-17 11:53:00 | 显示全部楼层
看看行不行
  1. Sub kkk()
  2. Dim entry As AcadLineType
  3.     Dim found As Boolean
  4.     found = False
  5.     For Each entry In ThisDrawing.Linetypes
  6.         If StrComp(entry.Name, "acad_iso05w100", 1) = 0 Then
  7.             found = True
  8.             Exit For
  9.         End If
  10.     Next
  11.     If Not (found) Then ThisDrawing.Linetypes.Load "acad_iso05w100", "acadiso.lin"
  12.    
  13.    
  14.    
  15. Dim fzpl As AcadPolyline
  16. Dim zbd As Variant
  17. Dim zbd1 As Variant
  18. Dim i As Integer
  19. Dim blist() As Double
  20. Dim lcx As AcadLayer
  21. Set lcx = ThisDrawing.Layers.Add("虚线层")
  22. lcx.Color = acCyan
  23. On Error Resume Next
  24. Do
  25. If IsEmpty(zbd1) Then
  26.   zbd = ThisDrawing.Utility.GetPoint(, "第一点:")
  27.   Else
  28.   zbd = ThisDrawing.Utility.GetPoint(zbd1, "下一点:")
  29.   End If
  30.   
  31.   
  32.   If Err Then
  33.     Err.Clear
  34.     Exit Do
  35.   End If
  36.   ReDim Preserve blist(3 * i + 2)
  37.   blist(3 * i) = zbd(0): blist(3 * i + 1) = zbd(1): blist(3 * i + 2) = zbd(2)
  38.   i = i + 1
  39.   
  40.   zbd1 = zbd
  41. Loop
  42. Set fzpl = ThisDrawing.ModelSpace.AddPolyline(blist)
  43. fzpl.Linetype = "acad_iso05w100"
  44. fzpl.Layer = "虚线层"
  45. End Sub
回复

使用道具 举报

26

主题

589

帖子

10

银币

中流砥柱

Rank: 25

铜币
693
发表于 2003-11-17 12:04:00 | 显示全部楼层
知道了起点和第二点之后就可以八绘制一条多段线了,以后的点通过AddVertex来添加。
  1. Sub Example_AddVertex()
  2.     ' This example creates a light weight polyline in model space.
  3.     ' It then adds a vertex to the polyline.
  4.     Dim plineObj As AcadLWPolyline
  5.     Dim points(0 To 9) As Double
  6.    
  7.    
  8.     ' Define the 2D polyline points
  9.     points(0) = 1: points(1) = 1
  10.     points(2) = 1: points(3) = 2
  11.     points(4) = 2: points(5) = 2
  12.     points(6) = 3: points(7) = 2
  13.     points(8) = 4: points(9) = 4
  14.         
  15.     ' Create a light weight Polyline object in model space
  16.     Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
  17.     ZoomAll
  18.     MsgBox "Add a vertex to the end of the polyline.", , "AddVertex Example"
  19.    
  20.     ' Define the new vertex
  21.     Dim newVertex(0 To 1) As Double
  22.     newVertex(0) = 4: newVertex(1) = 1
  23.    
  24.     ' Add the vertex to the polyline
  25.     plineObj.AddVertex 5, newVertex
  26.     plineObj.Update
  27.     MsgBox "Vertex added.", , "AddVertex Example"
  28.    
  29. End Sub
回复

使用道具 举报

28

主题

117

帖子

4

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
229
发表于 2003-11-17 12:36:00 | 显示全部楼层
完善一下:
  1. Sub kkk()
  2. Dim entry As AcadLineType
  3.     Dim found As Boolean
  4.     found = False
  5.     For Each entry In ThisDrawing.Linetypes
  6.         If StrComp(entry.Name, "acad_iso05w100", 1) = 0 Then
  7.             found = True
  8.             Exit For
  9.         End If
  10.     Next
  11.     If Not (found) Then ThisDrawing.Linetypes.Load "acad_iso05w100", "acadiso.lin"
  12.    
  13.    
  14.    
  15. Dim fzpl As AcadPolyline
  16. Dim zbd As Variant
  17. Dim zbd1 As Variant
  18. Dim i As Integer
  19. Dim blist() As Double
  20. Dim lcx As AcadLayer
  21. Set lcx = ThisDrawing.Layers.Add("虚线层")
  22. lcx.Color = acCyan
  23. On Error Resume Next
  24. Do
  25. If IsEmpty(zbd1) Then
  26.   zbd = ThisDrawing.Utility.GetPoint(, "第一点:")
  27.   Else
  28.   zbd = ThisDrawing.Utility.GetPoint(zbd1, "下一点:")
  29.   End If
  30.   
  31.   
  32.   If Err Then
  33.     Err.Clear
  34.     Exit Do
  35.   End If
  36.   ReDim Preserve blist(3 * i + 2)
  37.   blist(3 * i) = zbd(0): blist(3 * i + 1) = zbd(1): blist(3 * i + 2) = zbd(2)
  38.   i = i + 1
  39.   
  40.   
  41.   If i = 1 Then
  42.   GoTo ppp
  43.   End If
  44.   
  45.   If i = 2 Then
  46.   Dim start(0 To 5) As Double
  47.   start(0) = zbd1(0)
  48.   start(1) = zbd1(1)
  49.   start(2) = zbd1(2)
  50.   start(3) = zbd(0)
  51.   start(4) = zbd(1)
  52.   start(5) = zbd(2)
  53.   
  54.   Set fzpl = ThisDrawing.ModelSpace.AddPolyline(start)
  55.   fzpl.Linetype = "acad_iso05w100"
  56. fzpl.Layer = "虚线层"
  57. fzpl.Update
  58.   GoTo ppp
  59.    
  60.   End If
  61.   
  62.   
  63.   fzpl.Coordinates = blist
  64.   fzpl.Update
  65. ppp:
  66. zbd1 = zbd
  67. Loop
  68. fzpl.Coordinates = blist
  69. End Sub
回复

使用道具 举报

11

主题

39

帖子

8

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
83
发表于 2003-11-17 14:05:00 | 显示全部楼层
非常好,感谢topirol的热心帮助!!!
回复

使用道具 举报

6

主题

60

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
84
发表于 2003-11-17 17:12:00 | 显示全部楼层
真的比偶作的简单多了~~~~~
偶地代码就不好意思贴了~~~
回复

使用道具 举报

21

主题

166

帖子

7

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
250
发表于 2003-11-21 19:49:00 | 显示全部楼层
再有闭合和回退功能就更完善了!谢谢topiro!!
还请有空完善。
回复

使用道具 举报

28

主题

117

帖子

4

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
229
发表于 2003-11-24 14:09:00 | 显示全部楼层

功能可以实现,不过我觉得代码不是很好,将就吧,希望有人再来完善一下
  1. Sub kkk1()
  2. Dim entry As AcadLineType
  3.     Dim found As Boolean
  4.     found = False
  5.     For Each entry In ThisDrawing.Linetypes
  6.         If StrComp(entry.Name, "acad_iso05w100", 1) = 0 Then
  7.             found = True
  8.             Exit For
  9.         End If
  10.     Next
  11.     If Not (found) Then ThisDrawing.Linetypes.Load "acad_iso05w100", "acadiso.lin"
  12.    
  13.    
  14.    
  15. Dim fzpl As AcadPolyline
  16. Dim zbd As Variant
  17. Dim zbd1 As Variant
  18. Dim startpoint As Variant
  19. Dim i As Integer
  20. Dim j As Integer
  21. Dim blist() As Double
  22. Dim lcx As AcadLayer
  23. Set lcx = ThisDrawing.Layers.Add("虚线层")
  24. lcx.Color = acCyan
  25. On Error Resume Next
  26.      Dim keywordList As String
  27.     keywordList = "Close Undo"
  28.    
  29.    
  30. Do
  31. If IsEmpty(zbd1) Then
  32.   zbd = ThisDrawing.Utility.GetPoint(, "第一点:")
  33.   startpoint = zbd
  34.   Else
  35. restart:
  36.   ThisDrawing.Utility.InitializeUserInput 128, keywordList
  37.   zbd = ThisDrawing.Utility.GetPoint(zbd1, "下一点[闭合(C)/后退(U)]:")
  38.         If Err Then
  39.   
  40.                     If Err.Number = -2147467259 Then
  41.                             Dim inputString As String
  42.                              Err.Clear
  43.                              inputString = ThisDrawing.Utility.GetInput
  44.                                     If inputString = "Close" Then
  45.                                        fzpl.Closed = True
  46.                                     End If
  47.                                     If inputString = "Undo" Then
  48.                                     i = i - 2
  49.                                     If i = 0 Then
  50.                                     
  51.                                     fzpl.Delete
  52.                                     zbd1 = startpoint
  53.                                     blist(0) = zbd1(0)
  54.                                     blist(1) = zbd1(1)
  55.                                     blist(2) = zbd1(2)
  56.                                     i = 1
  57.                                     GoTo restart
  58.                                     'End
  59.                                     End If
  60.                                     If i < 0 Then
  61.                                     End
  62.                                     End If
  63.                                     ReDim Preserve blist(3 * i + 2)
  64.                                     GoTo endundo
  65.                                     End If
  66.                                     
  67.                                     
  68.                                      Exit Do
  69.                      End If
  70.         End If
  71.         
  72.   End If
  73.   If Err Then
  74.          
  75.                     Err.Clear
  76.                     Exit Do
  77.    
  78.               
  79.   End If
  80.   ReDim Preserve blist(3 * i + 2)
  81.   blist(3 * i) = zbd(0): blist(3 * i + 1) = zbd(1): blist(3 * i + 2) = zbd(2)
  82.   If i = 0 Then
  83.   zbd1 = zbd
  84.   GoTo ppploop
  85.   End If
  86.   
  87.   If i = 1 Then
  88.   
  89.   Dim start(0 To 5) As Double
  90.   start(0) = blist(0)
  91.   start(1) = blist(1)
  92.   start(2) = blist(2)
  93.   start(3) = blist(3)
  94.   start(4) = blist(4)
  95.   start(5) = blist(5)
  96.   
  97.   Set fzpl = ThisDrawing.ModelSpace.AddPolyline(start)
  98.   fzpl.Linetype = "acad_iso05w100"
  99. fzpl.Layer = "虚线层"
  100. fzpl.Update
  101. zbd1 = zbd
  102.   GoTo ppploop
  103.    
  104.   End If
  105.   
  106. endundo:
  107.   fzpl.Coordinates = blist
  108.   
  109.   fzpl.Update
  110. j = (UBound(fzpl.Coordinates) + 1) / 3
  111. zbd1 = fzpl.Coordinate(j - 1)
  112. ppploop:
  113. i = i + 1
  114. Loop
  115. fzpl.Coordinates = blist
  116. End Sub
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-6-29 12:21 , Processed in 1.999250 second(s), 69 queries .

© 2020-2025 乐筑天下

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