明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1934|回复: 6

班主,我的外扩内扩问题,怎么没人回答呀?

[复制链接]
发表于 2003-11-12 09:20:00 | 显示全部楼层 |阅读模式
See the topic
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=12402

我的意思是向四周扩,和原来的闭全图形等距离。
发表于 2003-11-12 23:00:00 | 显示全部楼层
做成图块,然后计算按不等比例插入方式插入。
发表于 2003-11-13 07:34:00 | 显示全部楼层
再详细一点:
先取得要外扩的图形做为选择集;
通过选择集的每一对象取得总的选择集的长(X)和宽(Y)以及中心CP)(用GetBoundingBox方法 );
将选择集生成的图块(用WBlock);
按照需要的外扩的值(Z)计算X向和Y向的插入比例:
X1=(X+2Z)/X
Y1=(Y+2Z)/Y
由于生成图块的方法没有提供插入点功能,所以要取得图块的中心点然后再移动图块到原先选择集的中心点。
这样就结束了。
 楼主| 发表于 2003-11-13 09:07:00 | 显示全部楼层
能给段代码吗?
发表于 2003-11-13 11:42:00 | 显示全部楼层
没有时间整理好一点,也没有加入出错捕捉语句:


  1. Sub ExObjs()
  2. '先取得要外扩的图形做为选择集;
  3.     Dim ss As AcadSelectionSet
  4.     Set ss = CreateSelectionSet
  5.     ss.SelectOnScreen
  6.     Dim z As Double
  7.     z = ThisDrawing.Utility.GetDistance(, "输入扩边的距离:")
  8. '通过选择集的每一对象取得总的选择集的长(X)和宽(Y)以及中心CP)(用GetBoundingBox方法 );
  9.     Dim box As Variant
  10.     box = ssExtents(ss)
  11.     Dim cp As Variant
  12.     Dim x As Double
  13.     Dim y As Double
  14.     cp = GetCenterPoint(box, x, y)
  15.    
  16. '按照需要的外扩的值(Z)计算X向和Y向的插入比例:
  17.     Dim x1 As Double
  18.     Dim y1 As Double
  19.     x1 = (x + 2 * z) / x
  20.     y1 = (y + 2 * z) / y
  21. '将选择集生成的图块
  22.     Dim objBlk As AcadBlock
  23.     Set objBlk = ThisDrawing.Blocks.Add(cp, "*U")
  24.     Dim varObjs As Variant
  25.     varObjs = sset2var(ss)
  26.     ThisDrawing.CopyObjects varObjs, objBlk
  27.    
  28.     Dim blkName As String
  29.     blkName = objBlk.Name
  30.     Dim blkref As AcadBlockReference
  31.     Set blkref = ThisDrawing.ModelSpace.InsertBlock(cp, blkName, x1, y1, 1, 0)
  32.     'blkref.Explode
  33.     'blkref.Delete
  34. End Sub

  35. Function GetCenterPoint(points As Variant, ByRef x As Double, ByRef y As Double) As Variant
  36.     Dim i As Integer
  37.     Dim cp(2) As Double
  38.     Dim MaxPnt As Variant
  39.     Dim MinPnt As Variant
  40.     MinPnt = points(0)
  41.     MaxPnt = points(1)
  42.     cp(0) = (MinPnt(0) + MaxPnt(0)) / 2
  43.     cp(1) = (MinPnt(1) + MaxPnt(1)) / 2
  44.     x = MaxPnt(0) - MinPnt(0)
  45.     y = MaxPnt(1) - MinPnt(1)
  46.     GetCenterPoint = cp
  47. End Function
  48. Public Function CreateSelectionSet(Optional ssName As String = "ss") As AcadSelectionSet

  49.     Dim ss As AcadSelectionSet
  50.    
  51.     On Error Resume Next
  52.     Set ss = ThisDrawing.SelectionSets(ssName)
  53.     If Err Then Set ss = ThisDrawing.SelectionSets.Add(ssName)
  54.     ss.Clear
  55.     Set CreateSelectionSet = ss

  56. End Function

  57. Public Function Extents(points)

  58.     Dim min, max
  59.     Dim i As Long, j As Long, pt, retVal(0 To 1)
  60.    
  61.     min = points(LBound(points))
  62.     max = points(LBound(points))
  63.         
  64.     For i = LBound(points) To UBound(points)
  65.         pt = points(i)
  66.         For j = LBound(pt) To UBound(pt)
  67.             If pt(j) < min(j) Then min(j) = pt(j)
  68.             If pt(j) > max(j) Then max(j) = pt(j)
  69.         Next
  70.     Next
  71.    
  72.     retVal(0) = min: retVal(1) = max
  73.     Extents = retVal

  74. End Function

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

  76.     Dim points(), c As Long

  77.     Dim min, max, util As AcadUtility
  78.    
  79.     Set util = ThisDrawing.Utility
  80.    
  81.     c = 0
  82.    
  83.     For i = 0 To ss.Count - 1
  84.         
  85.         ss.Item(i).GetBoundingBox min, max
  86.         min = util.TranslateCoordinates(min, acWorld, acUCS, False)
  87.         max = util.TranslateCoordinates(max, acWorld, acUCS, False)
  88.         ReDim Preserve points(0 To c + 1)
  89.         points(c) = min: points(c + 1) = max
  90.         c = c + 2
  91.         
  92.     Next
  93.         
  94.     ssExtents = Extents(points)

  95. End Function

  96. Function sset2var(ss As AcadSelectionSet) As Variant
  97.     Dim i As Integer
  98.     Dim varObjs() As AcadEntity
  99.     i = ss.Count - 1
  100.     ReDim varObjs(i) As AcadEntity
  101.     For i = 0 To ss.Count - 1
  102.      Set varObjs(i) = ss(i)
  103.     Next
  104.     sset2var = varObjs
  105.    
  106. End Function
 楼主| 发表于 2003-11-14 09:13:00 | 显示全部楼层
So thanks
我看看,问题再问你!
发表于 2003-11-14 21:09:00 | 显示全部楼层
又发现ActiveX的一个BUG。
插入图块时,如果图块X、Y比例不同时,则插入后不能用Explode方法炸开。只能用SendCommand方法引用命令的方式炸开。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-28 13:40 , Processed in 0.187365 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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