明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

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

关于交点的问题

  [复制链接]
发表于 2008-8-30 00:06:00 | 显示全部楼层
重新生成
 楼主| 发表于 2008-9-4 15:06:00 | 显示全部楼层

哎,最终还是没有解决掉,难道明经里面这么多人没有一个人会吗?

发表于 2008-9-4 17:37:00 | 显示全部楼层
本帖最后由 作者 于 2008-9-4 17:57:18 编辑

写了一段,还有bug,下班了,回去捣鼓捣鼓
  1. Sub inserttxt()
  2. '定义π
  3. Const pi = 3.1415
  4. '声明线变量
  5. Dim obj As AcadEntity
  6. '声明点坐标变量
  7. Dim pt As Variant
  8. '选择线
  9. ThisDrawing.Utility.GetEntity obj, pt, vbNewLine + "选择要插入文字的线: "
  10. '声明文字对象变量
  11. Dim txt As AcadText
  12. '添加文字对象
  13. Set txt = ThisDrawing.ModelSpace.AddText("测试", pt, ThisDrawing.GetVariable("textsize"))
  14. '声明文字对象左下角坐标变量及右上角坐标变量
  15. Dim lpt As Variant
  16. Dim rpt As Variant
  17. '求文字对象左下角坐标及右上角坐标
  18. txt.GetBoundingBox lpt, rpt
  19. '声明文字宽度变量
  20. Dim txtwidth As Double
  21. '求文字宽度
  22. txtwidth = Abs(lpt(0) - rpt(0))
  23. '修改文字对齐方式为居中对齐
  24. txt.Alignment = acAlignmentMiddleCenter
  25. '文字归位
  26. txt.TextAlignmentPoint = pt
  27. '声明交点坐标数组变量
  28. Dim ipt() As Double
  29. '求文字和线的交点
  30. ipt = txt.IntersectWith(obj, acExtendBoth)
  31. '声明交点坐标变量
  32. Dim pt1(0 To 2) As Double
  33. Dim pt2(0 To 2) As Double
  34. '求交点坐标
  35. pt1(0) = ipt(0)
  36. pt1(1) = ipt(1)
  37. pt1(2) = ipt(2)
  38. pt2(0) = ipt(3)
  39. pt2(1) = ipt(4)
  40. pt2(2) = ipt(5)
  41. '声明角度变量
  42. Dim ang As Double
  43. '求角度
  44. ang = ThisDrawing.Utility.AngleFromXAxis(pt1, pt2)
  45. '修正角度
  46. If pi * 0.5 < ang And ang <= pi * 1.5 Then ang = ang + pi
  47. '修正文字角度
  48. txt.Rotation = ang
  49. '声明打断点坐标变量
  50. Dim bpt1 As Variant
  51. Dim bpt2 As Variant
  52. '求打断点坐标
  53. bpt1 = ThisDrawing.Utility.PolarPoint(pt, ang, txtwidth * 0.7)
  54. bpt2 = ThisDrawing.Utility.PolarPoint(pt, ang + pi, txtwidth * 0.7)
  55. '打断
  56. ThisDrawing.SendCommand ( _
  57. "(command " & _
  58. Chr(34) & "break" & Chr(34) & _
  59. "(handent " & _
  60. Chr(34) & obj.Handle & Chr(34) & _
  61. ")" & _
  62. Chr(34) & "none" & Chr(34) & _
  63. "(list " & bpt1(0) & " " & bpt1(1) & " " & bpt1(2) & ")" & _
  64. Chr(34) & "none" & Chr(34) & _
  65. "(list " & bpt2(0) & " " & bpt2(1) & " " & bpt2(2) & ")) " _
  66. )
  67. End Sub
发表于 2008-9-4 18:25:00 | 显示全部楼层
换一种方式,测试一下
  1. Sub inserttxt()
  2. On Error Resume Next
  3. '定义π
  4. Const pi = 3.1415
  5. '声明点坐标变量
  6. Dim pt As Variant
  7. '选择点
  8. pt = ThisDrawing.Utility.GetPoint(, "选择要插入文字的线段: ")
  9. '声明一个临时选择集
  10. Dim sset As AcadSelectionSet
  11. ThisDrawing.SelectionSets.Add ("temp")
  12. Set sset = ThisDrawing.SelectionSets("temp")
  13. '定义过滤器
  14. Dim ft(0) As Integer
  15. Dim fd(0) As Variant
  16. ft(0) = 0
  17. fd(0) = "*LINE"
  18. '选择线
  19. sset.SelectAtPoint pt, ft, fd
  20. '有没有选到线
  21. If sset.Count > 0 Then
  22. '声明线变量
  23. Dim obj As AcadEntity
  24. '取得线
  25. Set obj = sset.Item(0)
  26. '声明文字对象变量
  27. Dim txt As AcadText
  28. '添加文字对象
  29. Set txt = ThisDrawing.ModelSpace.AddText("测试", pt, ThisDrawing.GetVariable("textsize"))
  30. '声明文字对象左下角坐标变量及右上角坐标变量
  31. Dim lpt As Variant
  32. Dim rpt As Variant
  33. '求文字对象左下角坐标及右上角坐标
  34. txt.GetBoundingBox lpt, rpt
  35. '声明文字宽度变量
  36. Dim txtwidth As Double
  37. '求文字宽度
  38. txtwidth = Abs(lpt(0) - rpt(0))
  39. '修改文字对齐方式为居中对齐
  40. txt.Alignment = acAlignmentMiddleCenter
  41. '文字归位
  42. txt.TextAlignmentPoint = pt
  43. '声明交点坐标数组变量
  44. Dim ipt() As Double
  45. '求文字和线的交点
  46. ipt = txt.IntersectWith(obj, acExtendBoth)
  47. '声明交点坐标变量
  48. Dim pt1(0 To 2) As Double
  49. Dim pt2(0 To 2) As Double
  50. '求交点坐标
  51. pt1(0) = ipt(0)
  52. pt1(1) = ipt(1)
  53. pt1(2) = ipt(2)
  54. pt2(0) = ipt(3)
  55. pt2(1) = ipt(4)
  56. pt2(2) = ipt(5)
  57. '声明角度变量
  58. Dim ang As Double
  59. '求角度
  60. ang = ThisDrawing.Utility.AngleFromXAxis(pt1, pt2)
  61. '修正角度
  62. If pi * 0.5 < ang And ang <= pi * 1.5 Then ang = ang + pi
  63. '修正文字角度
  64. txt.Rotation = ang
  65. '声明打断点坐标变量
  66. Dim bpt1 As Variant
  67. Dim bpt2 As Variant
  68. '求打断点坐标
  69. bpt1 = ThisDrawing.Utility.PolarPoint(pt, ang, txtwidth * 0.7)
  70. bpt2 = ThisDrawing.Utility.PolarPoint(pt, ang + pi, txtwidth * 0.7)
  71. '打断
  72. ThisDrawing.SendCommand ( _
  73. "(command " & _
  74. Chr(34) & "break" & Chr(34) & _
  75. "(handent " & _
  76. Chr(34) & obj.Handle & Chr(34) & _
  77. ")" & _
  78. Chr(34) & "none" & Chr(34) & _
  79. "(list " & bpt1(0) & " " & bpt1(1) & " " & bpt1(2) & ")" & _
  80. Chr(34) & "none" & Chr(34) & _
  81. "(list " & bpt2(0) & " " & bpt2(1) & " " & bpt2(2) & ")) " _
  82. )
  83. End If
  84. '删除临时选集
  85. sset.Delete
  86. End Sub
发表于 2008-9-4 18:31:00 | 显示全部楼层
增加圆弧和圆支持
  1. Sub inserttxt()
  2. On Error Resume Next
  3. '定义π
  4. Const pi = 3.1415
  5. '声明点坐标变量
  6. Dim pt As Variant
  7. '选择点
  8. pt = ThisDrawing.Utility.GetPoint(, "选择要插入文字的线段: ")
  9. '声明一个临时选择集
  10. Dim sset As AcadSelectionSet
  11. ThisDrawing.SelectionSets.Add ("temp")
  12. Set sset = ThisDrawing.SelectionSets("temp")
  13. '定义过滤器
  14. Dim ft(0) As Integer
  15. Dim fd(0) As Variant
  16. ft(0) = 0
  17. fd(0) = "*LINE,arc,circle"
  18. '选择线
  19. sset.SelectAtPoint pt, ft, fd
  20. '有没有选到线
  21. If sset.Count > 0 Then
  22. '声明线变量
  23. Dim obj As AcadEntity
  24. '取得线
  25. Set obj = sset.Item(0)
  26. '声明文字对象变量
  27. Dim txt As AcadText
  28. '添加文字对象
  29. Set txt = ThisDrawing.ModelSpace.AddText("测试", pt, ThisDrawing.GetVariable("textsize"))
  30. '声明文字对象左下角坐标变量及右上角坐标变量
  31. Dim lpt As Variant
  32. Dim rpt As Variant
  33. '求文字对象左下角坐标及右上角坐标
  34. txt.GetBoundingBox lpt, rpt
  35. '声明文字宽度变量
  36. Dim txtwidth As Double
  37. '求文字宽度
  38. txtwidth = Abs(lpt(0) - rpt(0))
  39. '修改文字对齐方式为居中对齐
  40. txt.Alignment = acAlignmentMiddleCenter
  41. '文字归位
  42. txt.TextAlignmentPoint = pt
  43. '声明交点坐标数组变量
  44. Dim ipt() As Double
  45. '求文字和线的交点
  46. ipt = txt.IntersectWith(obj, acExtendBoth)
  47. '声明交点坐标变量
  48. Dim pt1(0 To 2) As Double
  49. Dim pt2(0 To 2) As Double
  50. '求交点坐标
  51. pt1(0) = ipt(0)
  52. pt1(1) = ipt(1)
  53. pt1(2) = ipt(2)
  54. pt2(0) = ipt(3)
  55. pt2(1) = ipt(4)
  56. pt2(2) = ipt(5)
  57. '声明角度变量
  58. Dim ang As Double
  59. '求角度
  60. ang = ThisDrawing.Utility.AngleFromXAxis(pt1, pt2)
  61. '修正角度
  62. If pi * 0.5 < ang And ang <= pi * 1.5 Then ang = ang + pi
  63. '修正文字角度
  64. txt.Rotation = ang
  65. '声明打断点坐标变量
  66. Dim bpt1 As Variant
  67. Dim bpt2 As Variant
  68. '求打断点坐标
  69. bpt1 = ThisDrawing.Utility.PolarPoint(pt, ang, txtwidth * 0.7)
  70. bpt2 = ThisDrawing.Utility.PolarPoint(pt, ang + pi, txtwidth * 0.7)
  71. '打断
  72. ThisDrawing.SendCommand ( _
  73. "(command " & _
  74. Chr(34) & "break" & Chr(34) & _
  75. "(handent " & _
  76. Chr(34) & obj.Handle & Chr(34) & _
  77. ")" & _
  78. Chr(34) & "none" & Chr(34) & _
  79. "(list " & bpt1(0) & " " & bpt1(1) & " " & bpt1(2) & ")" & _
  80. Chr(34) & "none" & Chr(34) & _
  81. "(list " & bpt2(0) & " " & bpt2(1) & " " & bpt2(2) & ")) " _
  82. )
  83. End If
  84. '删除临时选集
  85. sset.Delete
  86. End Sub
发表于 2012-5-8 23:02:55 | 显示全部楼层
请问你找到解决两组多段线求交点的程序吗?能共享吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-25 16:22 , Processed in 0.166640 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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