乐筑天下

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

[编程交流] 添加/更改颜色

[复制链接]

14

主题

28

帖子

14

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
70
发表于 2022-7-6 11:31:56 | 显示全部楼层 |阅读模式
你好
 
我正在构建一个矩形阵列,这些矩形被分成若干组。我需要这些不同颜色的组。
 
我在循环中使用此命令:
 
设置An=ObjAcad。ActiveDocument。模型空间。添加LightweightPolyline(点)
 
我想添加一个命令来更改此多段线的颜色。
 
请告知
 
非常感谢。
 
凯特01
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 12:03:28 | 显示全部楼层
例子:
 
  1. An.Color = acGreen
回复

使用道具 举报

14

主题

28

帖子

14

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
70
发表于 2022-7-6 12:25:14 | 显示全部楼层
谢谢
 
也许我误解了你的答案。试过了,没有改变颜色。
 
请附上excel文件。例程位于VBA部分
 
谢谢
MAKE_FRAGMENTED\u AutoCad\u CADTUTOR\u 20100317\u 1230PM。拉链
回复

使用道具 举报

1

主题

1069

帖子

1050

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
69
发表于 2022-7-6 12:40:21 | 显示全部楼层
 
尝试此代码
  1. Public Sub Fragmented_Autocad()
  2. Dim points() As Double
  3. Dim acadApp  As AcadApplication
  4. '=======================================
  5. A$ = "########0.0"
  6. On Error Resume Next ' GESTION DES ERREURS
  7. Set acadApp = GetObject(, "AutoCAD.Application")
  8. If Err Then
  9. Err.Clear
  10. On Error GoTo 0
  11. End If
  12. Set acadApp = CreateObject("AutoCAD.Application.17") ''<--18 for A2010
  13. If Err Then
  14. MsgBox Err.Description
  15. Exit Sub
  16. End If
  17. acadApp.Visible = True ' AUTOCAD
  18. Set AcadDoc = acadApp.ActiveDocument
  19. Set AcadUtil = AcadDoc.Utility
  20. AcadDoc.ActiveSpace = acModelSpace
  21. ' ======================================================================
  22. N = 33  '
  23. ' ======================================================================
  24. ReDim points(0 To 9) As Double
  25. Lunitcell = 105.41
  26. dx = Lunitcell / (N + 0.2) ' mm - corresponds to 1/8 inch sheet
  27. dy = dx ' mm
  28. dz = dx ' mm
  29. m = Int(N / 2)
  30. Overlap = dx / 10
  31. Lx = dx + 2 * Overlap ' Pixel Size
  32. Ly = dy + 2 * Overlap
  33. lz = dz + 2 * Overlap
  34. For I = 1 To N / 2 ' loop on x
  35. For J = 1 To I  ' loop on y
  36. uk = Rnd(I + J)
  37. uk = 1
  38. If uk > 0.5 Then
  39. 'Q1 - x=minus - y=minus - x=i - y=j - Q1 - Q1 - Q1 - Q1 - Q1 - Q1 - Q1 - Q1 - Q1 - Q1 - Q1 - Q1 - Q1 - Q1 - Q1 - Q1 - Q1 - Q1 - Q1 - Q1 - Q1 - Q1 - Q1 - Q1
  40. x1 = -(m * dx + Lx / 2 - dx * (I - 1)): y1 = -(m * dy + Ly / 2 - dy * (J - 1)): x2 = x1 + Lx: y2 = y1 + Ly
  41. points(0) = x1: points(1) = -y1: points(2) = x2: points(3) = -y1: points(4) = x2: points(5) = -y2: points(6) = x1: points(7) = -y2: points( = x1: points(9) = -y1
  42. Debug.Print "Q1 ", points(0), points(1), points(2), points(3), points(4), points(5), points(6), points(7), points(
  43. Set An = AcadDoc.ModelSpace.AddLightWeightPolyline(points) ' add points (nodes)
  44. An.Color = acGreen
  45. 'Q2 - x=minus - y=minus - x=j - y=i - Q2 - Q2 - Q2 - Q2 - Q2 - Q2 - Q2 - Q2 - Q2 - Q2 - Q2 - Q2 - Q2 - Q2 - Q2 - Q2 - Q2 - Q2 - Q2 - Q2 - Q2 - Q2 - Q2 - Q2
  46. If I <> J Then
  47. x1 = -(m * dx + Lx / 2 - dx * (J - 1)): y1 = -(m * dy + Ly / 2 - dy * (I - 1)): x2 = x1 + Lx: y2 = y1 + Ly
  48. points(0) = x1: points(1) = -y1: points(2) = x2: points(3) = -y1: points(4) = x2: points(5) = -y2: points(6) = x1: points(7) = -y2: points( = x1: points(9) = -y1
  49. Set An = AcadDoc.ModelSpace.AddLightWeightPolyline(points) ' add points (nodes)
  50. An.Color = acblue
  51. End If
  52. 'Q3 -x = plus - y = minus - x = J - y = I - Q3 - Q3 - Q3 - Q3 - Q3 - Q3 - Q3 - Q3 - Q3 - Q3 - Q3 - Q3 - Q3 - Q3 - Q3 - Q3 - Q3 - Q3 - Q3 - Q3 - Q3 - Q3 - Q3 - Q3
  53. x1 = (m * dx + Lx / 2 - dx * (I - 1)): y1 = -(m * dy + Ly / 2 - dy * (J - 1)): x2 = x1 - Lx: y2 = y1 + Ly
  54. points(0) = x1: points(1) = -y1: points(2) = x2: points(3) = -y1: points(4) = x2: points(5) = -y2: points(6) = x1: points(7) = -y2: points( = x1: points(9) = -y1
  55. Set An = AcadDoc.ModelSpace.AddLightWeightPolyline(points) ' add points (nodes)
  56. An.Color = acYellow
  57. 'Q4 - x=plus - y=minus - x=i - y=j - Q4 - Q4 - Q4 - Q4 - Q4 - Q4 - Q4 - Q4 - Q4 - Q4 - Q4 - Q4 - Q4 - Q4 - Q4 - Q4 - Q4 - Q4 - Q4 - Q4 - Q4 - Q4 - Q4 - Q4
  58. If I <> J Then
  59. x1 = (m * dx + Lx / 2 - dx * (J - 1)): y1 = -(m * dy + Ly / 2 - dy * (I - 1)): x2 = x1 - Lx: y2 = y1 + Ly
  60. points(0) = x1: points(1) = -y1: points(2) = x2: points(3) = -y1: points(4) = x2: points(5) = -y2: points(6) = x1: points(7) = -y2: points( = x1: points(9) = -y1
  61. Set An = AcadDoc.ModelSpace.AddLightWeightPolyline(points) ' add points (nodes)
  62. An.Color = acMagenta
  63. End If
  64. 'Q5 - x=plus - y=plus - x=j - y=i - Q5 - Q5 - Q5 - Q5 - Q5 - Q5 - Q5 - Q5 - Q5 - Q5 - Q5 - Q5 - Q5 - Q5 - Q5 - Q5 - Q5 - Q5 - Q5 - Q5 - Q5 - Q5 - Q5 - Q5
  65. x1 = (m * dx + Lx / 2 - dx * (I - 1)): y1 = (m * dy + Ly / 2 - dy * (J - 1)): x2 = x1 - Lx: y2 = y1 - Ly
  66. points(0) = x1: points(1) = -y1: points(2) = x2: points(3) = -y1: points(4) = x2: points(5) = -y2: points(6) = x1: points(7) = -y2: points( = x1: points(9) = -y1
  67. An.Color = aclightblue
  68. Set An = AcadDoc.ModelSpace.AddLightWeightPolyline(points) ' add points (nodes)
  69. 'Q6 - x=plus - y=plus - x=j - y=i - Q6 - Q6 - Q6 - Q6 - Q6 - Q6 - Q6 - Q6 - Q6 - Q6 - Q6 - Q6 - Q6 - Q6 - Q6 - Q6 - Q6 - Q6 - Q6 - Q6 - Q6 - Q6 - Q6 - Q6
  70. If I <> J Then
  71. x1 = (m * dx + Lx / 2 - dx * (J - 1)): y1 = (m * dy + Ly / 2 - dy * (I - 1)):: x2 = x1 - Lx: y2 = y1 - Ly
  72. points(0) = x1: points(1) = -y1: points(2) = x2: points(3) = -y1: points(4) = x2: points(5) = -y2: points(6) = x1: points(7) = -y2: points( = x1: points(9) = -y1
  73. Set An = AcadDoc.ModelSpace.AddLightWeightPolyline(points) ' add points (nodes)
  74. An.Color = acBlack
  75. End If
  76. 'Q7 - x=minus - y=plus - x=j - y=i - Q7 - Q7 - Q7 - Q7 - Q7 - Q7 - Q7 - Q7 - Q7 - Q7 - Q7 - Q7 - Q7 - Q7 - Q7 - Q7 - Q7 - Q7 - Q7 - Q7 - Q7 - Q7 - Q7 - Q7
  77. x1 = -(m * dx + Lx / 2 - dx * (I - 1)): y1 = (m * dy + Ly / 2 - dy * (J - 1)): x2 = x1 + Lx: y2 = y1 - Ly
  78. points(0) = x1: points(1) = -y1: points(2) = x2: points(3) = -y1: points(4) = x2: points(5) = -y2: points(6) = x1: points(7) = -y2: points( = x1: points(9) = -y1
  79. Debug.Print "Q7 ", points(0), points(1), points(2), points(3), points(4), points(5), points(6), points(7), points(
  80. An.Color = acYellow
  81. Set An = AcadDoc.ModelSpace.AddLightWeightPolyline(points) ' add points (nodes)
  82. 'Q8 -x = minus - y = plus - x = I - y = J - Q8 - Q8 - Q8 - Q8 - Q8 - Q8 - Q8 - Q8 - Q8 - Q8 - Q8 - Q8 - Q8 - Q8 - Q8 - Q8 - Q8 - Q8 - Q8 - Q8 - Q8 - Q8 - Q8 - Q8
  83. If I <> J Then
  84. x1 = -(m * dx + Lx / 2 - dx * (J - 1)): y1 = (m * dy + Ly / 2 - dy * (I - 1)): x2 = x1 + Lx: y2 = y1 - Ly
  85. points(0) = x1: points(1) = -y1: points(2) = x2: points(3) = -y1: points(4) = x2: points(5) = -y2: points(6) = x1: points(7) = -y2: points( = x1: points(9) = -y1
  86. Set An = AcadDoc.ModelSpace.AddLightWeightPolyline(points) ' add points (nodes)
  87. An.Color = acYellow
  88. End If
  89. End If
  90. Next J
  91. Next I
  92. For k = 1 To N
  93. x1 = -(m * dx + Lx / 2 - dx * (k - 1)): y1 = -Ly / 2: x2 = x1 + Lx: y2 = y1 + Ly
  94. points(0) = x1: points(1) = -y1: points(2) = x2: points(3) = -y1: points(4) = x2: points(5) = -y2: points(6) = x1: points(7) = -y2: points( = x1: points(9) = -y1
  95. An.Color = acYellow
  96. Set An = AcadDoc.ModelSpace.AddLightWeightPolyline(points) ' add points (nodes)
  97. Next k
  98. For k = 1 To N
  99. If k <> Int(N / 2) + 1 Then
  100. x1 = -Lx / 2: y1 = -(m * dx + Lx / 2 - dx * (k - 1)): x2 = x1 + Lx: y2 = y1 + Ly
  101. points(0) = x1: points(1) = -y1: points(2) = x2: points(3) = -y1: points(4) = x2: points(5) = -y2: points(6) = x1: points(7) = -y2: points( = x1: points(9) = -y1
  102. Set An = AcadDoc.ModelSpace.AddLightWeightPolyline(points) ' add points (nodes)
  103. An.Color = acYellow
  104. End If
  105. Next k
  106. Close 1
  107. End Sub

 
~'J'~
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-6 02:27 , Processed in 0.393172 second(s), 60 queries .

© 2020-2025 乐筑天下

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