明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1559|回复: 0

求出某一图元和图上其他图元的所有交点,并新建一个“交点图层”,在所有交点处画一

[复制链接]
发表于 2006-5-3 11:32:00 | 显示全部楼层 |阅读模式
求出某一图元和图上其他图元的所有交点,并新建一个“交点图层”,在所有交点处画一个半径为5的圆[br]
  1. Option Explicit
  2. '求出某一图元和图上其他图元的所有交点,并新建一个“交点图层”,在所有交点处画一个半径为5的圆
  3. Public Sub aaa()
  4. On Error Resume Next
  5. Dim ent1 As AcadEntity
  6. Dim ent2 As AcadEntity
  7. Dim sset As AcadSelectionSet
  8. ThisDrawing.Utility.GetEntity ent1, "", "选择要求交点的图元:"
  9. Dim ptmin As Variant
  10. Dim ptmax As Variant
  11. 'ptmin,ptmax分别是图元ent1的最小外接矩形的左下角坐标和右上角坐标
  12. ent1.GetBoundingBox ptmin, ptmax
  13. Dim lay01 As AcadLayer
  14. Dim lay11 As AcadLayer
  15. Dim findlay As Integer
  16. findlay = 0 '寻找图层的结果的变量,0没有找到,1找到
  17. For Each lay01 In ThisDrawing.Layers '在所有的图层中进行循环
  18.   If lay01.Name = "交点图层" Then '如果找到图层名
  19.     findlay = 1 '把变量改为1标志着图层已经找到
  20.        If Not lay01.LayerOn Then lay01.LayerOn = True '打开
  21.        ThisDrawing.ActiveLayer = lay01 '把当前图层设为已经存在的图层
  22.     End If
  23.   Exit For '结束寻找
  24. Next lay01
  25. If findlay = 0 Then '没有找到图层
  26.   Set lay11 = ThisDrawing.Layers.Add("交点图层") '增加一个名为“交点图层”的图层
  27.   lay11.color = 1 '图层设置为红色
  28.   ThisDrawing.ActiveLayer = lay11 '将当前图层设置为交点图层
  29. End If
  30. '安全创建选择集
  31. If Not IsNull(ThisDrawing.SelectionSets.Item("exa")) Then
  32. Set sset = ThisDrawing.SelectionSets.Item("exa")
  33. sset.Delete
  34. End If
  35. Set sset = ThisDrawing.SelectionSets.Add("exa")
  36. '构造以ptmin,ptmax为界的交叉选择集
  37. sset.Select acSelectionSetCrossing, ptmin, ptmax
  38. '从选择集中删除ent1图元
  39. Dim objArray(0 To 0) As AcadEntity
  40.     Set objArray(0) = ent1
  41.     sset.RemoveItems objArray
  42. '循环选择集
  43. For Each ent2 In sset
  44. Call Draw_Circle(ent1, ent2)
  45. Next ent2
  46. End Sub
  47. '子函数
  48. '作用是:求两个图元的交点,并在交点处画一个半径为5的圆
  49. Private Function Draw_Circle(ByVal ent11 As AcadEntity, ByVal ent22 As AcadEntity) As AcadEntity
  50. Dim pts As Variant
  51. Dim cir As AcadCircle
  52. Dim pt(0 To 2) As Double
  53. pts = ent11.IntersectWith(ent22, acExtendNone)
  54. Dim I As Integer
  55. Dim str As String
  56. If VarType(pts) <> vbEmpty Then
  57. For I = LBound(pts) To UBound(pts) Step 3
  58. pt(0) = pts(I): pt(1) = pts(I + 1): pt(2) = pts(I + 2)
  59. Set cir = ThisDrawing.ModelSpace.AddCircle(pt, 5)
  60. Next I
  61. End If
  62. End Function

本帖子中包含更多资源

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

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

本版积分规则

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

GMT+8, 2025-2-22 05:30 , Processed in 0.158170 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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