明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 912|回复: 5

求助 面域布尔运算 赋值时报错 ——类型不匹配

[复制链接]
发表于 2015-1-20 13:45:38 | 显示全部楼层 |阅读模式
本帖最后由 xueliang123 于 2015-1-20 13:46 编辑
  1. Public Sub createcage()
  2. Dim dbpoint As Variant
  3. Dim halfwidth As Double

  4. Dim Hlength As Double
  5. Hlength = 110
  6. Dim outframpoint(0 To 7) As Double
  7. Dim inframpoint(0 To 7) As Double
  8. Dim cagecenter(0 To 2) As Double
  9. Dim cageradius As Double
  10. halfwidth = 255
  11. cageradius = 350

  12. Dim incircle(0 To 0) As AcadCircle
  13. Dim outcircle(0 To 0) As AcadCircle

  14. Dim outfram(0 To 0) As AcadEntity
  15. Dim infram(0 To 0) As AcadEntity
  16. '用户获取点并赋值以方便以后使用
  17. dbpoint = ThisDrawing.Utility.GetPoint(, "Select a point")
  18. cagecenter(0) = dbpoint(0) + 355: cagecenter(1) = dbpoint(1): cagecenter(2) = dbpoint(2)

  19. With ThisDrawing.ModelSpace
  20. Set incircle(0) = .AddCircle(cagecenter, cageradius)
  21. Set outcircle(0) = .AddCircle(cagecenter, cageradius + 5)
  22.    
  23. '画外框
  24. outframpoint(0) = dbpoint(0): outframpoint(1) = dbpoint(1) + halfwidth
  25. outframpoint(2) = dbpoint(0) + Hlength: outframpoint(3) = dbpoint(1) + halfwidth
  26. outframpoint(4) = dbpoint(0) + Hlength: outframpoint(5) = dbpoint(1) - halfwidth
  27. outframpoint(6) = dbpoint(0): outframpoint(7) = dbpoint(1) - halfwidth
  28. Set outfram(0) = .AddLightWeightPolyline(outframpoint)
  29. outfram(0).Closed = True
  30. '画内框
  31. inframpoint(0) = dbpoint(0): inframpoint(1) = dbpoint(1) + halfwidth - 5
  32. inframpoint(2) = dbpoint(0) + Hlength: inframpoint(3) = dbpoint(1) + halfwidth - 5
  33. inframpoint(4) = dbpoint(0) + Hlength: inframpoint(5) = dbpoint(1) - halfwidth + 5
  34. inframpoint(6) = dbpoint(0): inframpoint(7) = dbpoint(1) - halfwidth + 5
  35. Set infram(0) = .AddLightWeightPolyline(inframpoint)
  36. infram(0).Closed = True
  37. '面域图形到
  38. Dim regions(0 To 3) As Variant
  39. regions(0) = .AddRegion(outcircle):  regions(1) = .AddRegion(incircle)
  40. regions(2) = .AddRegion(outfram):  regions(3) = .AddRegion(infram)

  41. '将面域复制
  42. Dim A, B, C, D As AcadRegion


  43. Set A = regions(0): Set B = regions(1): Set C = regions(2): Set D = regions(3)
  44. A.Boolean acSubtraction, B: C.Boolean acSubtraction, D


  45. End With


  46. End Sub


 楼主| 发表于 2015-1-20 13:47:59 | 显示全部楼层
将47,50 ,51 加引号注释就运行很好 ,求高手帮忙看看
 楼主| 发表于 2015-1-20 13:49:47 | 显示全部楼层
这个却运行的很好,不知道上面那个程序是哪里错了
  1. Sub Ch4_CreateCompositeRegions()
  2. ' 创建两个圆,一个代表房间,
  3. ' 另外一个为房间中心的柱子

  4. Dim RoomObjects(0 To 1) As AcadCircle

  5. Dim center(0 To 2) As Double

  6. Dim radius As Double

  7. center(0) = 4

  8. center(1) = 4

  9. center(2) = 0

  10. radius = 2#

  11. Set RoomObjects(0) = ThisDrawing.ModelSpace.AddCircle(center, radius)

  12. radius = 1#

  13. Set RoomObjects(1) = ThisDrawing.ModelSpace.AddCircle(center, radius)

  14.   
  15. ' 用两个圆创建面域

  16. Dim regions As Variant

  17. regions = ThisDrawing.ModelSpace.AddRegion(RoomObjects)
  18. ' 将面域复制到面域变体中以方便使用

  19. Dim RoundRoomObj As AcadRegion

  20. Dim PillarObj As AcadRegion

  21.   

  22. If regions(0).Area > regions(1).Area Then

  23. ' 第一个面域为房间

  24. Set RoundRoomObj = regions(0)

  25. Set PillarObj = regions(1)

  26. Else

  27. ' 第一个面域为柱子

  28. Set PillarObj = regions(0)

  29. Set RoundRoomObj = regions(1)
  30. End If

  31.   

  32. ' 将房间颜色设为红色,柱子颜色设为青色

  33. RoundRoomObj.color = acRed

  34. PillarObj.color = acCyan

  35. ZoomAll

  36.   

  37. ' 从地板空间中减去柱子的空间

  38. ' 以得到代表总的地毯面积的面域。

  39. RoundRoomObj.Boolean acSubtraction, PillarObj

  40.   

  41. ' 使用Area属性以确定总的地毯面积

  42. MsgBox "地毯面积为: " & RoundRoomObj.Area

  43. End Sub
 楼主| 发表于 2015-1-20 13:52:15 | 显示全部楼层
D:\Capture.JPG
 楼主| 发表于 2015-1-20 13:53:22 | 显示全部楼层
程序运行附图

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2015-1-20 15:01:52 | 显示全部楼层
AddRegion返回的是数组/variant
不是数组的成员!!!!
regions(0) = .AddRegion(outcircle) 这当然不对了!
还有Dim A, B, C, D As AcadRegion,把ABC也定义成AcadRegion,而不应该是variant
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-25 12:48 , Processed in 0.147257 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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