- 积分
- 5838
- 明经币
- 个
- 注册时间
- 2003-4-28
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2003-10-9 13:40:00
|
显示全部楼层
用曲线类重写了程序,错误依旧。毛病出在Pt = ObjCurve.GetPointAtDistance(dist)这一句,而且每次出错时写入文件的点数都不一样,有多有少。真是百思不得其解!
- Sub GetPointAtSpline()
- Const ds As Double = 20 '曲线上的取点间隔
- Dim dist As Double '点至曲线端点的距离
- Dim SsetObj As AcadSelectionSet '选择集对象
- Dim SsetName As String '选择集名称
- Dim LengthOfCurve As Double '曲线全长
- Dim Pt As Variant '点坐标
- Dim i As Integer, j As Integer, num As Integer
- Dim gpCode(0) As Integer
- Dim dataValue(0) As Variant
- Dim groupCode As Variant, dataCode As Variant
-
- ThisDrawing.SendCommand "(vl-load-com)" & vbCr
-
- '定义引用曲线类模块
- Dim ObjCurve As Curve
- Set ObjCurve = New Curve
-
- '选择集名称
- SsetName = "SplineSet"
- '建立选择集
- On Error Resume Next
- Set SsetObj = ThisDrawing.SelectionSets.Add(SsetName)
- If Err Then
- Set SsetObj = ThisDrawing.SelectionSets.Item(SsetName)
- SsetObj.Clear
- Err.Clear
- End If
- On Error GoTo 0
-
- '将全部样条曲线添加到选择集
- gpCode(0) = 0
- dataValue(0) = "Spline"
- groupCode = gpCode
- dataCode = dataValue
- SsetObj.Select acSelectionSetAll, , , groupCode, dataCode
-
- '打开文件用于存储样条曲线离散化后的点的坐标
- Open "D:\curve.txt" For Output As #1
- Print #1, "样条曲线数目:" & SsetObj.Count
-
- '在样条曲线上每隔一定距离取一个点,依次将点的坐标写入文件
- For i = 1 To SsetObj.Count
- Set ObjCurve.Entity = SsetObj.Item(i - 1)
- '取得曲线全长
- LengthOfCurve = ObjCurve.length
- '计算要分的整段数
- num = Int(LengthOfCurve / ds)
- Print #1, "第" & i & "样条曲线长度:" & LengthOfCurve & " 曲线点数:" & num + 2
- '起点
- Pt = ObjCurve.StartPoint
- Print #1, "1: "; Format(Pt(0), "0.000"); " "; Format(Pt(1), "0.000"); " "; Format(Pt(2), "0.000")
- '中间各点
- For j = 1 To num
- dist = ds * j
- Pt = ObjCurve.GetPointAtDistance(dist)
- Print #1, j + 1 & ": "; Format(Pt(0), "0.000"); " "; Format(Pt(1), "0.000"); " "; Format(Pt(2), "0.000")
- Next j
- '终点
- Pt = ObjCurve.EndPoint
- Print #1, num + 2 & ": "; Format(Pt(0), "0.000"); " "; Format(Pt(1), "0.000"); " "; Format(Pt(2), "0.000")
- Next i
- Close 1
- SsetObj.Delete
-
- MsgBox "坐标提取成功"
-
- End Sub
|
|