明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖
楼主: topirol

如何获得整个文档的BoundingBox?

  [复制链接]
发表于 2003-12-10 11:06:00 | 显示全部楼层
把图形中的所有对象做成一个图块,只用一次的取边框就行,这样速度会快很多吧
 楼主| 发表于 2003-12-10 11:36:00 | 显示全部楼层
请问用什么方法来把选择集转成一个图块?
发表于 2003-12-10 14:01:00 | 显示全部楼层
将选择集中的对象转换到一个数组中,然后通过数组来生成图块,再插入图块。
ssArray  返回包含于选择集中每一项目的变体数组  
http://www.mjtd.com/function/list.asp?id=333&ordertype=bysort&orderkey=33
 楼主| 发表于 2003-12-10 15:11:00 | 显示全部楼层
用图块的办法代码是简单一些,但不知道怎么回事,测试起来好像比前面的办法还要慢:(

  1. '方法1
  2. Sub getdrawingbox1() '通过制作图块再求图块的boundingbox
  3. Dim bk As AcadBlock
  4. Dim bror As AcadBlockReference
  5. Dim ss As AcadSelectionSet
  6. Dim po(0 To 2) As Double
  7. On Error Resume Next

  8. po(0) = 0
  9. po(1) = 0
  10. po(2) = 0

  11. Dim boxp(0 To 1) As Variant
  12. Set bk = ThisDrawing.Blocks.Add(po, "tempb")



  13. Set ss = ThisDrawing.SelectionSets("ssss")
  14. If Err Then
  15. Err.Clear

  16. Set ss = ThisDrawing.SelectionSets.Add("ssss")

  17. End If

  18. ss.Select acSelectionSetAll



  19. ThisDrawing.CopyObjects ssArray(ss), bk
  20. Set bror = ThisDrawing.ModelSpace.InsertBlock(po, "tempb", 1, 1, 1, 0)

  21. bror.GetBoundingBox boxp(0), boxp(1)
  22. Dim poly1 As AcadPolyline
  23. Dim pllist(0 To 11) As Double
  24. pllist(0) = boxp(0)(0)
  25. pllist(1) = boxp(0)(1)
  26. pllist(2) = 0
  27. pllist(3) = boxp(0)(0)
  28. pllist(4) = boxp(1)(1)
  29. pllist(5) = 0
  30. pllist(6) = boxp(1)(0)
  31. pllist(7) = boxp(1)(1)
  32. pllist(8) = 0
  33. pllist(9) = boxp(1)(0)
  34. pllist(10) = boxp(0)(1)
  35. pllist(11) = 0
  36. ss.Clear
  37. bror.Delete
  38. bk.Delete
  39. Set poly1 = ThisDrawing.ModelSpace.AddPolyline(pllist)
  40. poly1.Closed = True
  41. poly1.Color = 1

  42. End Sub

  43. Function ssArray(ss As AcadSelectionSet)

  44.     Dim retVal() As AcadEntity, i As Long
  45.    
  46.     ReDim retVal(0 To ss.Count - 1)
  47.    
  48.     For i = 0 To ss.Count - 1
  49.         Set retVal(i) = ss.Item(i)
  50.     Next
  51.    
  52.     ssArray = retVal

  53. End Function



  54. '******************************方法2
  55. Sub getdrawingbox2() '通过各个实体的boundingbox求出

  56. Dim acaddoc As AcadDocument
  57. Set acaddoc = ThisDrawing
  58. Dim ss As AcadSelectionSet
  59. On Error Resume Next

  60. Set ss = acaddoc.SelectionSets("ssss")
  61. If Err Then
  62. Err.Clear
  63. Set ss = acaddoc.SelectionSets.Add("ssss")
  64. End If

  65. ss.Clear


  66. ss.Select acSelectionSetAll

  67. Dim poinsss As Variant
  68. boxp = ssExtents(ss)



  69. Dim poly1 As AcadPolyline
  70. Dim pllist(0 To 11) As Double
  71. pllist(0) = boxp(0)(0)
  72. pllist(1) = boxp(0)(1)
  73. pllist(2) = 0
  74. pllist(3) = boxp(0)(0)
  75. pllist(4) = boxp(1)(1)
  76. pllist(5) = 0
  77. pllist(6) = boxp(1)(0)
  78. pllist(7) = boxp(1)(1)
  79. pllist(8) = 0
  80. pllist(9) = boxp(1)(0)
  81. pllist(10) = boxp(0)(1)
  82. pllist(11) = 0
  83. ss.Clear
  84. bror.Delete
  85. bk.Delete
  86. Set poly1 = ThisDrawing.ModelSpace.AddPolyline(pllist)
  87. poly1.Closed = True
  88. poly1.Color = 1
  89. ss.Clear
  90. ss.Delete
  91. End Sub

  92. Public Function ssExtents(ss As AcadSelectionSet) As Variant

  93.     Dim points(), c As Long

  94.     Dim min, max, util As AcadUtility
  95.    
  96.     Set util = ThisDrawing.Utility
  97.    
  98.     c = 0
  99.    
  100.     For i = 0 To ss.Count - 1
  101.         
  102.         ss.Item(i).GetBoundingBox min, max
  103.         min = util.TranslateCoordinates(min, acWorld, acUCS, False)
  104.         max = util.TranslateCoordinates(max, acWorld, acUCS, False)
  105.         ReDim Preserve points(0 To c + 1)
  106.         points(c) = min: points(c + 1) = max
  107.         c = c + 2
  108.         
  109.     Next
  110.         
  111.     ssExtents = Extents(points)

  112. End Function

  113. Public Function Extents(points)

  114.     Dim min, max
  115.     Dim i As Long, j As Long, pt, retVal(0 To 1)
  116.    
  117.     min = points(LBound(points))
  118.     max = points(LBound(points))
  119.         
  120.     For i = LBound(points) To UBound(points)
  121.         pt = points(i)
  122.         For j = LBound(pt) To UBound(pt)
  123.             If pt(j) < min(j) Then min(j) = pt(j)
  124.             If pt(j) > max(j) Then max(j) = pt(j)
  125.         Next
  126.     Next
  127.    
  128.     retVal(0) = min: retVal(1) = max
  129.     Extents = retVal

  130. End Function




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

本版积分规则

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

GMT+8, 2024-11-28 12:34 , Processed in 0.170705 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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