明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1363|回复: 3

求助!!

[复制链接]
发表于 2004-10-20 12:22:00 | 显示全部楼层 |阅读模式
Sub SelectSp()
On Error Resume Next
Dim SSpline As AcadSelectionSet
Dim SLine As AcadSelectionSet
Dim fd(0) As Integer, ft(0)
Dim Pline As AcadLine
Dim s, t

Dim pInsertPnt()
Set SSpline = ThisDrawing.SelectionSets.Add("Spline")
fd(0) = "Spline": ft(0) = 0
SSpline.Select acSelectionSetAll, , , ft, fd
Set SLine = ThisDrawing.SelectionSets.Add("Line")
fd(0) = "Line": ft(0) = 0
SLine.Select acSelectionSetAll, , , ft, fd
For Each Pline In SLine
For s = 0 To SSpline.Count - 1
pInsertPnt = Pline.IntersectWith(SSpline(s), acExtendNone)
Next s
Next Pline
Dim i As Integer, j As Integer, k As Integer
Dim str As String
If VarType(pInsertPnt) <> vbEmpty Then
For i = LBound(pInsertPnt) To UBound(pInsertPnt)
str = "Intersection Point[" & k & "] is: " & pInsertPnt(j) & "," & pInsertPnt(j + 1) & "," & pInsertPnt(j + 2)
MsgBox str, , "IntersectWith Example"
str = ""
i = i + 2
j = j + 3
k = k + 1
Next
End If
End Sub

上图是运行上面一段代码后的结果,我想求直线与曲线的交点并输出。结果…… 请问大侠们用insertwith求得的交点是怎么储存在数组里的啊??帮助文档里的例子为什么是i=i+2,,j=j+3。我想把求得的交点按照x坐标进行排序再输出应该怎么办呢?

本帖子中包含更多资源

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

x
发表于 2004-10-20 19:16:00 | 显示全部楼层
Intersection方法只能求对象与对象间的交点,而不是选择集与选择集间的交点。
发表于 2004-10-20 20:54:00 | 显示全部楼层
本帖最后由 作者 于 2004-10-20 21:37:16 编辑
  1. Sub SelectSp()
  2.        On Error Resume Next
  3.        Dim SSpline As AcadSelectionSet
  4.        Dim SLine As AcadSelectionSet
  5.        Dim ft(0) As Integer, fd(0)
  6.        Dim Pline As AcadLine
  7.        Dim s, t
  8.        Dim i As Integer, j As Integer, k As Integer
  9.        Dim str As String
  10.        Dim pInsertPnt
  11.    
  12.        ThisDrawing.SelectionSets("Spline").Delete
  13.        ThisDrawing.SelectionSets("Line").Delete
  14.       
  15.        Set SSpline = ThisDrawing.SelectionSets.Add("Spline")
  16.        ft(0) = 0: fd(0) = "Spline"
  17.        SSpline.Select acSelectionSetAll, , , ft, fd
  18.       
  19.        Set SLine = ThisDrawing.SelectionSets.Add("Line")
  20.        ft(0) = 0: fd(0) = "Line"
  21.        SLine.Select acSelectionSetAll, , , ft, fd
  22.       
  23.        For Each Pline In SLine
  24.                For s = 0 To SSpline.Count - 1
  25.                        pInsertPnt = Pline.IntersectWith(SSpline(s), acExtendNone)
  26.                        j = 0
  27.                        For i = 0 To UBound(pInsertPnt)
  28.                                str = "Intersection Point[" & k & "] is: " & pInsertPnt(j) & "," & pInsertPnt(j + 1) & "," & pInsertPnt(j + 2)
  29.                                MsgBox str, , "IntersectWith Example"
  30.                                str = ""
  31.                                i = i + 2
  32.                                j = j + 3
  33.                                k = k + 1
  34.                        Next
  35.                Next s
  36.        Next Pline
  37. End Sub
 楼主| 发表于 2004-10-21 22:49:00 | 显示全部楼层
谢谢两位老大的教导啦! 都是小弟我看明经出的《AutoCAD VBA 开发精彩实例教程》不够认真,这两天发现好多问题在书上都有例子了。十分感谢版主们热心回答我的问题!!! 呵呵,小弟我还有个问题.???? For i = 0 To UBound(pInsertPnt)
str = "Intersection Point[" & k & "] is: " & pInsertPnt(j) & "," & pInsertPnt(j + 1) & "," & pInsertPnt(j + 2)
MsgBox str, , "IntersectWith Example"
str = ""
[U]i = i + 2[/U] j = j + 3
k = k + 1
Next
上面那段代码中为什么i = i + 2, i的取值范围不是由交点的个数决定的吗,每个交点由x y z三个坐标啊。还请可爱的版主同志回答一下小弟这个菜菜的问题,谢谢啦
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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