明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 663|回复: 1

VBA中的将一段程序编程块的问题

[复制链接]
发表于 2015-6-18 09:44:51 | 显示全部楼层 |阅读模式
纯新手,在网上找了很多关于VBA变成块的问题,但是还是不知道怎么操作,还有,就是镜像后的图形能保存快么,下面是我画的图形,不知道怎么写块,求大神指点下,然后我自己琢磨,谢谢各位对新手的指教。


  1. Private Sub CommandButton1_Click()



  2. '#############################################################################图幅起始点

  3. Dim x, y, z As Double

  4. '线性添加
  5. Dim entry As AcadLineType
  6. Dim found As Boolean
  7. Dim Itname(0 To 3) As String
  8. Dim i As Integer
  9. found = False
  10. '添加三种线型
  11. Itname(0) = "BORDER"
  12. Itname(1) = "CENTER"
  13. Itname(2) = "DASHDOT"
  14. Itname(3) = "DASHED"
  15. For i = 0 To 3
  16. '搜寻要添加的线型在集合中是否存在
  17. For Each entry In ThisDrawing.Linetypes
  18. If StrComp(entry.Name, Itname(i), 1) = 0 Then
  19. found = True
  20. Exit For
  21. End If
  22. Next
  23. '如果不存在将其从文件acadiso.lin中加载
  24. If Not (found) Then
  25. ThisDrawing.Linetypes.Load Itname(i), "acadiso.lin"
  26. End If
  27. Next
  28. Dim objline(1 To 2000)  As AcadLine
  29. Dim objarc(1 To 2000)  As AcadArc
  30. Dim objcircle(1 To 2000) As AcadCircle


  31. '#############################################################################主视图




  32. Dim zc As Double

  33. x = 1000
  34. y = 1000
  35. z = 0
  36. zc = 0

  37. Dim pt01(2) As Double
  38. Dim pt02(2) As Double
  39. Dim pt03(2) As Double
  40. Dim pt04(2) As Double
  41. Dim pt05(2) As Double
  42. Dim pt06(2) As Double
  43. Dim pt07(2) As Double
  44. Dim pt08(2) As Double
  45. Dim pt09(2) As Double
  46. Dim pt10(2) As Double

  47. Dim pt11(2) As Double
  48. Dim pt12(2) As Double
  49. Dim pt13(2) As Double
  50. Dim pt14(2) As Double
  51. Dim pt15(2) As Double
  52. Dim pt16(2) As Double
  53. Dim pt17(2) As Double
  54. Dim pt18(2) As Double
  55. Dim pt19(2) As Double
  56. Dim pt20(2) As Double

  57. Dim pt95(2) As Double
  58. Dim pt96(2) As Double


  59. pt01(0) = x: pt01(1) = y: pt01(2) = z
  60. pt02(0) = x: pt02(1) = y + 40: pt02(2) = z
  61. pt03(0) = x: pt03(1) = y + 47: pt03(2) = z
  62. pt04(0) = x: pt04(1) = y + 50: pt04(2) = z
  63. pt05(0) = x: pt05(1) = y + 57: pt05(2) = z
  64. pt06(0) = x + 3.3: pt06(1) = y + 57: pt06(2) = z
  65. pt07(0) = x + 3.3: pt07(1) = y + 50: pt07(2) = z
  66. pt08(0) = x + 8.9: pt08(1) = y + 50: pt08(2) = z
  67. pt09(0) = x + 8.9: pt09(1) = y + 47: pt09(2) = z
  68. pt10(0) = x + 40: pt10(1) = y + 47: pt10(2) = z
  69. pt11(0) = x + 40: pt11(1) = y + 40: pt11(2) = z
  70. pt12(0) = x + 90: pt12(1) = y + 40: pt12(2) = z
  71. pt13(0) = x + 90: pt13(1) = y: pt13(2) = z
  72. pt14(0) = x + 4.5: pt14(1) = y + 50: pt14(2) = z
  73. pt15(0) = x + 4.5: pt15(1) = y + 47: pt15(2) = z
  74. pt16(0) = x + 35: pt16(1) = y + 47: pt16(2) = z
  75. pt17(0) = x + 35: pt17(1) = y + 40: pt17(2) = z

  76. pt95(0) = x: pt95(1) = y + 75: pt95(2) = z
  77. pt96(0) = x: pt96(1) = y - zc - 613: pt96(2) = z


  78. Dim objLayer As AcadLayer
  79. Set objLayer = ThisDrawing.Layers.Add("粗实线")
  80. objLayer.color = acWhite
  81. objLayer.Linetype = "Continuous"
  82. objLayer.Lineweight = acLnWt030
  83. ThisDrawing.ActiveLayer = objLayer



  84. Set objline(1) = ThisDrawing.ModelSpace.AddLine(pt05, pt06)
  85. Set objline(2) = ThisDrawing.ModelSpace.AddLine(pt06, pt07)
  86. Set objline(3) = ThisDrawing.ModelSpace.AddLine(pt04, pt08)
  87. Set objline(4) = ThisDrawing.ModelSpace.AddLine(pt08, pt09)
  88. Set objline(5) = ThisDrawing.ModelSpace.AddLine(pt03, pt10)
  89. Set objline(6) = ThisDrawing.ModelSpace.AddLine(pt10, pt11)
  90. Set objline(7) = ThisDrawing.ModelSpace.AddLine(pt02, pt12)
  91. Set objline(8) = ThisDrawing.ModelSpace.AddLine(pt12, pt13)
  92. Set objline(9) = ThisDrawing.ModelSpace.AddLine(pt01, pt13)
  93. Set objline(10) = ThisDrawing.ModelSpace.AddLine(pt14, pt15)
  94. Set objline(11) = ThisDrawing.ModelSpace.AddLine(pt16, pt17)


  95. Dim xhcs As Integer
  96. For xhcs = 1 To 11
  97. objline(xhcs).Mirror pt95, pt96
  98. Next







  99. End Sub




发表于 2015-6-20 23:28:58 | 显示全部楼层

  1. Private Sub CommandButton1_Click()   '点击按钮_程序





  2. '#############################################################################图幅起始点


  3. Dim x, y, z As Double


  4. '线性添加

  5. Dim entry As AcadLineType  '声明线型

  6. Dim found As Boolean

  7. Dim Itname(0 To 3) As String  '声明数组

  8. Dim i As Integer

  9. found = False

  10. '添加三种线型

  11. Itname(0) = "BORDER"

  12. Itname(1) = "CENTER"

  13. Itname(2) = "DASHDOT"

  14. Itname(3) = "DASHED"

  15. For i = 0 To 3

  16. '搜寻要添加的线型在集合中是否存在

  17. For Each entry In ThisDrawing.Linetypes   '在线型中循环

  18. If StrComp(entry.Name, Itname(i), 1) = 0 Then'如果线型名字为三种的一种

  19. found = True

  20. Exit For  '退出循环

  21. End If

  22. Next

  23. '如果不存在将其从文件acadiso.lin中加载

  24. If Not (found) Then

  25. ThisDrawing.Linetypes.Load Itname(i), "acadiso.lin" '如果不存在自动加载

  26. End If

  27. Next

  28. Dim objline(1 To 2000)  As AcadLine

  29. Dim objarc(1 To 2000)  As AcadArc

  30. Dim objcircle(1 To 2000) As AcadCircle




  31. '#############################################################################主视图







  32. Dim zc As Double


  33. x = 1000

  34. y = 1000

  35. z = 0

  36. zc = 0


  37. Dim pt01(2) As Double

  38. Dim pt02(2) As Double

  39. Dim pt03(2) As Double

  40. Dim pt04(2) As Double
  41. [b][b][b][/b][/b][/b]
  42. Dim pt05(2) As Double

  43. Dim pt06(2) As Double

  44. Dim pt07(2) As Double

  45. Dim pt08(2) As Double

  46. Dim pt09(2) As Double

  47. Dim pt10(2) As Double


  48. Dim pt11(2) As Double

  49. Dim pt12(2) As Double

  50. Dim pt13(2) As Double

  51. Dim pt14(2) As Double

  52. Dim pt15(2) As Double

  53. Dim pt16(2) As Double

  54. Dim pt17(2) As Double

  55. Dim pt18(2) As Double

  56. Dim pt19(2) As Double

  57. Dim pt20(2) As Double


  58. Dim pt95(2) As Double

  59. Dim pt96(2) As Double




  60. pt01(0) = x: pt01(1) = y: pt01(2) = z

  61. pt02(0) = x: pt02(1) = y + 40: pt02(2) = z

  62. pt03(0) = x: pt03(1) = y + 47: pt03(2) = z

  63. pt04(0) = x: pt04(1) = y + 50: pt04(2) = z

  64. pt05(0) = x: pt05(1) = y + 57: pt05(2) = z

  65. pt06(0) = x + 3.3: pt06(1) = y + 57: pt06(2) = z

  66. pt07(0) = x + 3.3: pt07(1) = y + 50: pt07(2) = z

  67. pt08(0) = x + 8.9: pt08(1) = y + 50: pt08(2) = z

  68. pt09(0) = x + 8.9: pt09(1) = y + 47: pt09(2) = z

  69. pt10(0) = x + 40: pt10(1) = y + 47: pt10(2) = z

  70. pt11(0) = x + 40: pt11(1) = y + 40: pt11(2) = z

  71. pt12(0) = x + 90: pt12(1) = y + 40: pt12(2) = z

  72. pt13(0) = x + 90: pt13(1) = y: pt13(2) = z

  73. pt14(0) = x + 4.5: pt14(1) = y + 50: pt14(2) = z

  74. pt15(0) = x + 4.5: pt15(1) = y + 47: pt15(2) = z

  75. pt16(0) = x + 35: pt16(1) = y + 47: pt16(2) = z

  76. pt17(0) = x + 35: pt17(1) = y + 40: pt17(2) = z


  77. pt95(0) = x: pt95(1) = y + 75: pt95(2) = z

  78. pt96(0) = x: pt96(1) = y - zc - 613: pt96(2) = z




  79. Dim objLayer As AcadLayer

  80. Set objLayer = ThisDrawing.Layers.Add("粗实线")

  81. objLayer.color = acWhite

  82. objLayer.Linetype = "Continuous"

  83. objLayer.Lineweight = acLnWt030

  84. ThisDrawing.ActiveLayer = objLayer





  85. Set objline(1) = ThisDrawing.ModelSpace.AddLine(pt05, pt06)

  86. Set objline(2) = ThisDrawing.ModelSpace.AddLine(pt06, pt07)

  87. Set objline(3) = ThisDrawing.ModelSpace.AddLine(pt04, pt08)

  88. Set objline(4) = ThisDrawing.ModelSpace.AddLine(pt08, pt09)

  89. Set objline(5) = ThisDrawing.ModelSpace.AddLine(pt03, pt10)

  90. Set objline(6) = ThisDrawing.ModelSpace.AddLine(pt10, pt11)

  91. Set objline(7) = ThisDrawing.ModelSpace.AddLine(pt02, pt12)

  92. Set objline(8) = ThisDrawing.ModelSpace.AddLine(pt12, pt13)

  93. Set objline(9) = ThisDrawing.ModelSpace.AddLine(pt01, pt13)

  94. Set objline(10) = ThisDrawing.ModelSpace.AddLine(pt14, pt15)

  95. Set objline(11) = ThisDrawing.ModelSpace.AddLine(pt16, pt17)




  96. Dim xhcs As Integer

  97. For xhcs = 1 To 11

  98. objline(xhcs).Mirror pt95, pt96

  99. Next











  100. End Sub
点击按钮名为command_1的按钮即可调用
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-25 11:59 , Processed in 0.168999 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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