明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1553|回复: 8

请问如何获得图形中特定点信息??

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



如上的地形等高线图中,红线表示一截面.请问怎么自动获得截面与等高线交点的数据(如坐标等).请问能够自动生成该截面的剖面图吗?


我是个初学者,请各位大侠多多指教.给点思路

本帖子中包含更多资源

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

x
发表于 2004-10-10 21:45:00 | 显示全部楼层
你的等高线是什么,下面是我以前写的Spline等高线的剖面测试
  1. Sub t9()
  2. On Error GoTo ErrHandle
  3. Dim ss As AcadSelectionSet
  4. Dim ssLine As AcadSelectionSet
  5. Dim ft(0) As Integer, fd(0)
  6. Dim p1(2) As Double, p2(2) As Double
  7. Dim pPnts()
  8. Dim pLine As AcadLine, dot
  9. Dim i, j
  10. Dim pInsertPnt
  11. Dim pInsertPnts()
  12. Dim pNum As Integer
  13. Dim pnt(2) As DoubleDim pStart, PEnd
  14. Dim pCount As Integer
  15. Dim pDistances() As Double
  16. Set ss = ThisDrawing.SelectionSets.Add("*TlsTest*")
  17. ft(0) = 0: fd(0) = "Spline"
  18. ss.Select acSelectionSetAll, , , ft, fd
  19. ReDim pPnts(ss.Count - 1)
  20. For i = 0 To ss.Count - 1
  21. pPnts(i) = ss(i).ControlPoints
  22. p1(2) = pPnts(i)(2)
  23. ss(i).Move p1, p2
  24. Next i
  25. Set ssLine = ThisDrawing.SelectionSets.Add("*TlsTestLine*")
  26. ft(0) = 0: fd(0) = "Line"ssLine.Select acSelectionSetAll, , , ft, fd
  27. For Each pLine In ssLine
  28. pNum = 0
  29. For i = 0 To ss.Count - 1
  30. pInsertPnt = pLine.IntersectWith(ss(i), acExtendNone)
  31. n = (UBound(pInsertPnt) + 1) / 3
  32. For j = 0 To n - 1
  33. pnt(0) = pInsertPnt(j * 3)
  34. pnt(1) = pInsertPnt(j * 3 + 1)
  35. pnt(2) = pPnts(i)(2)
  36. ReDim Preserve pInsertPnts(pNum)
  37. pInsertPnts(pNum) = pnt
  38. pNum = pNum + 1
  39. Next j
  40. Next ipStart = pLine.StartPoint
  41. PEnd = pLine.EndPoint
  42. pCount = UBound(pInsertPnts)If Abs(Tan(pLine.Angle)) < 1 Then pNum = 0 Else pNum = 1ReDim pDistances(pCount) As Double
  43. For i = 0 To pCount
  44. pDistances(i) = Abs(pInsertPnts(i)(pNum) - pStart(pNum))
  45. Next i
  46. SortPoint pDistances, pInsertPnts, pCount
  47. Dim pDPnts() As Double
  48. pNum = UBound(pInsertPnts) * 3 + 2
  49. ReDim pDPnts(pNum) As Double
  50. For i = 0 To UBound(pInsertPnts)
  51. pDPnts(i * 3) = pInsertPnts(i)(0)
  52. pDPnts(i * 3 + 1) = pInsertPnts(i)(1)
  53. pDPnts(i * 3 + 2) = pInsertPnts(i)(2)
  54. Next i
  55. ThisDrawing.ModelSpace.Add3DPoly(pDPnts).Rotate3D pLine.StartPoint, pLine.EndPoint, Atn(1) * 2
  56. Next pLine
  57. ErrHandle:
  58. For i = 0 To ss.Count - 1
  59. p1(2) = pPnts(i)(2)
  60. ss(i).Move p2, p1
  61. Next i
  62. ThisDrawing.SelectionSets("*TlsTest*").Delete
  63. ThisDrawing.SelectionSets("*TlsTestLine*").Delete
  64. End Sub
  65. Private Sub SortPoint(ByRef Values As Variant, ByRef Points As Variant, ByVal Count As Integer)
  66. '按值将点数组排序
  67. Dim pTemp As Double, pnt As VariantFor i = Count To 1 Step -1For j = 0 To i - 1If Values(j) > Values(j + 1) Then
  68. pTemp = Values(j + 1)
  69. Values(j + 1) = Values(j)
  70. Values(j) = pTemp
  71. pnt = Points(j + 1)
  72. Points(j + 1) = Points(j)
  73. Points(j) = pnt
  74. End IfNext jNext iEnd Sub
 楼主| 发表于 2004-10-11 11:31:00 | 显示全部楼层
谢谢斑竹的帮助!!我是个初学者,看这个程序有点困难。斑竹同志能不能再给小弟讲解一下


我的等高线是Spline吧
发表于 2004-10-11 17:52:00 | 显示全部楼层
先将曲线Move到Z=0,与直线求交点,再还原曲线
 楼主| 发表于 2004-10-12 08:42:00 | 显示全部楼层
谢谢斑竹热心答疑啦!

 楼主| 发表于 2004-10-13 09:15:00 | 显示全部楼层

再次麻烦版主了

版主同志好!!我实在是刚开始接触vba,有好多函数、方法都不懂。请问有什么书对这些有个详细的介绍呢??我现在在看MJTD推出的AutoCAD VBA 虽然收获不少,但还是有好多东西不会啊!我该怎么学习VBA呢??


我上面的图的等高线是扫描后矢量化的,我现在就连在平面上多条曲线和指定直线求交点都还不会,麻烦版主及各位前辈教教我!!

发表于 2004-10-13 19:40:00 | 显示全部楼层
先看看这 [WEB]http://www.vba.cn/object/acad2004/[/WEB]
 楼主| 发表于 2004-10-13 22:53:00 | 显示全部楼层
太谢谢版主了
 楼主| 发表于 2004-10-27 12:16:00 | 显示全部楼层

又来麻烦版主同志了

本帖最后由 作者 于 2004-10-27 23:06:41 编辑

小弟我把版主给我参考的剖面测试代码改了改,想在一个新的图形窗口画出所得的剖面。可是我创建了新的窗口后原来代码中的 ErrHandle:
For i = 0 To ss.Count - 1
p1(2) = pPnts(i)(2)
ss(i).Move p2, p1
Next i
ThisDrawing.SelectionSets("*TlsTest*").Delete
ThisDrawing.SelectionSets("*TlsTestLine*").Delete 就出现了错误(对象变量和with块变量未设置)。是不是因为新的窗口没有定义 i 和选择集,要切换到原来的图形窗口。请问我该怎么做呢? 再问一句,创建所得的剖面有什么好的是现代码吗? 剖面是以相邻两点的XOY投影距离为横坐标,高程差为纵坐标。我觉得我实现的好麻烦啊,头都晕了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-28 00:49 , Processed in 0.184830 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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