明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1116|回复: 9

求助高手帮忙修改下程序

[复制链接]
发表于 2008-8-12 10:10:00 | 显示全部楼层 |阅读模式

我想遍历图层"ab1"中的图块及图层"abcd"的闭合多段线,如果图块的坐标在闭合多段线的区域外,则把区域外的图块删除,如在闭合的区域内,则保留。

我想把图块的坐标点画圆,面域,把闭合多段线也进行面域,并求交,如有相交,则保留,没相交则删除,

可是我这个程序有问题,下面也不知道怎么编了,请高手帮帮忙,帮我修改一下。

Sub Example_Select()       '选择某图层的图块与多段线区域比较
Dim ssetObj As AcadSelectionSet
On Error Resume Next
Set ssetObj = ThisDrawing.SelectionSets.Add("SSET")
If Err <> 0 Then
Set ssetObj = ThisDrawing.SelectionSets.Item("SSET")
ssetObj.Clear
End If
    
Dim mode As Integer
Dim object As AcadEntity
   
mode = acSelectionSetAll

Dim gpCode(1) As Integer
Dim dataValue(1) As Variant
gpCode(0) = 0
dataValue(0) = "insert"
gpCode(1) = 8
dataValue(1) = "ab1"

Dim groupCode As Variant, dataCode As Variant
groupCode = gpCode
dataCode = dataValue
   
ssetObj.Select mode, , , groupCode, dataCode

'提示有几个对象加入选择集
MsgBox "图中有" & ssetObj.Count & "个图元已加入到选择集SSET中。"

'遍历程序
For i = 0 To ssetObj.Count - 1
Set object = ssetObj.Item(i)
Next i

'定义变量为变体型
Dim xy As Variant

'遍历选择集的对象
For Each ent In ssetObj

'求出块对象的坐标
xy = ent.InsertionPoint

'以下为绘制圆程序
Dim cobj(0 To 0) As AcadCircle
Set cobj(0) = ThisDrawing.ModelSpace.AddCircle(xy, 50)
cobj(0).Layer = "ab1"

'对圆进行面域
Dim regionobj As Variant
regionobj = ThisDrawing.ModelSpace.AddRegion(cobj)
cobj(0).Erase
Next

'MsgBox "坐标是:" & xy(0)

'''''''''''''
'以上部分为图块坐标提取程序

'''''''''''''''''''''''
'以下部分为多段线提取并面域
Dim ssetObj1 As AcadSelectionSet
Set ssetObj1 = ThisDrawing.SelectionSets.Add("SSET1")
If Err <> 0 Then
Set ssetObj1 = ThisDrawing.SelectionSets.Item("SSET1")
ssetObj1.Clear
End If
    
Dim mode1 As Integer
Dim object1(0 To 0) As AcadEntity
   
mode1 = acSelectionSetAll

Dim gpCode1(1) As Integer
Dim dataValue1(1) As Variant
gpCode1(0) = 0
dataValue1(0) = "LWPOLYLINE"
gpCode1(1) = 8
dataValue1(1) = "abcd"
   
Dim groupCode1 As Variant, dataCode1 As Variant
groupCode1 = gpCode1
dataCode1 = dataValue1
   
ssetObj1.Select mode1, , , groupCode1, dataCode1

'显示有几个图元加入选择集内
MsgBox "图中有" & ssetObj1.Count & "个图元已加入到选择集SSET中。"

For i1 = 0 To ssetObj1.Count - 1
Set object1(0) = ssetObj1.Item(i1)

If Not Err Then

Dim regionobj1 As Variant
regionobj1 = ThisDrawing.ModelSpace.AddRegion(object1)

End If
Next i1


Dim roundroomobj As AcadRegion
Dim pillarobj As AcadRegion
'If regionobj(0).Area > regionobj1(0).Area Then

Set roundroomobj = regionobj1(0)
Set pillarobj = regionobj(0)

'Else
'Set pillarobj = regionobj1(0)
'Set roundroomobj = regionobj(0)
'End If

roundroomobj.Color = acRed
pillarobj.Color = acCyan

roundroomobj.Boolean acIntersection, pillarobj

End Sub


发表于 2008-8-12 10:36:00 | 显示全部楼层

我的想法,通过过滤,选出abcd图层的多段线,然后创建新选集,通过选集SelectByPolygon,把选到的块添加到选集。删出选集中没有的块

 楼主| 发表于 2008-8-12 14:19:00 | 显示全部楼层
还是搞不来,请高手帮帮忙吧
发表于 2008-8-12 15:46:00 | 显示全部楼层

提供图纸测试

发表于 2008-8-12 17:25:00 | 显示全部楼层

改变下方法吧!判断块的插入点是否在多段线内(搜搜,有代码的),否就删了,

 楼主| 发表于 2008-8-12 19:02:00 | 显示全部楼层
本帖最后由 作者 于 2008-8-12 19:04:06 编辑

这个是图纸,请高手们帮忙

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-8-13 09:55:00 | 显示全部楼层

高手们,帮帮们吧,帮我编一下吧,我实在是编不出来了

发表于 2008-8-13 16:10:00 | 显示全部楼层
  1. Sub test()
  2. On Error Resume Next
  3. '多段线选集
  4. Dim plsltset As AcadSelectionSet
  5. ThisDrawing.SelectionSets.Add "plsltset"
  6. Set plsltset = ThisDrawing.SelectionSets.Item("plsltset")
  7. '初始化
  8. plsltset.Clear
  9. '过滤出abcd图层的多段线
  10. Dim ft(0 To 1) As Integer
  11. Dim fd(0 To 1) As Variant
  12. ft(0) = 0
  13. fd(0) = "LWPOLYLINE"
  14. ft(1) = 8
  15. fd(1) = "abcd"
  16. plsltset.Select acSelectionSetAll, , , ft, fd
  17. '块选集
  18. Dim blksltset As AcadSelectionSet
  19. ThisDrawing.SelectionSets.Add "blksltset"
  20. Set blksltset = ThisDrawing.SelectionSets.Item("blksltset")
  21. '初始化
  22. blksltset.Clear
  23. '多段线
  24. Dim plobj As AcadLWPolyline
  25. '块过滤
  26. ft(0) = 0
  27. fd(0) = "INSERT"
  28. ft(1) = 8
  29. fd(1) = "AB1"
  30. '遍历多段线选集选择块
  31. For Each plobj In plsltset
  32. '多段线顶点
  33. Dim plpts As Variant
  34. plpts = plobj.Coordinates
  35. '二维点转换为三维点
  36. ReDim sspts(0 To ((UBound(plpts) + 1) * 3 / 2 - 1)) As Double
  37. Dim j As Integer
  38. j = 0
  39. For i = 0 To UBound(plpts) - 1 Step 2
  40. sspts(j) = plpts(i)
  41. sspts(j + 1) = plpts(i + 1)
  42. sspts(j + 2) = 0
  43. j = j + 3
  44. Next
  45. '选择块
  46. blksltset.SelectByPolygon acSelectionSetCrossingPolygon, sspts, ft, fd
  47. Next
  48. '选择所有AB1图层上的块
  49. Dim allblksltset As AcadSelectionSet
  50. ThisDrawing.SelectionSets.Add "allblksltset"
  51. Set allblksltset = ThisDrawing.SelectionSets.Item("allblksltset")
  52. allblksltset.Select acSelectionSetAll, , , ft, fd
  53. ReDim objs(0 To blksltset.Count - 1) As Object
  54. '多边形内的所有对象
  55. For i = 0 To blksltset.Count - 1
  56. Set objs(i) = blksltset(i)
  57. Next
  58. '剔除多边形内的对象
  59. allblksltset.RemoveItems (objs)
  60. '删除其余对象
  61. allblksltset.Erase
  62. '收工
  63. End Sub
发表于 2008-8-13 16:43:00 | 显示全部楼层

楼上的写的非常不错

 楼主| 发表于 2008-8-13 19:30:00 | 显示全部楼层
谢谢楼上的兄弟了,我试用下
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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