edi-000 发表于 2007-10-16 11:29:00

[求助]关于获取样条曲线的拟合点问题(附代码)

<p>大侠们好!我现在已有一张CAD图,想通过VBA实现获取里面的所有样条曲线的拟合点的坐标,我的代码如下:</p><p>Sub Select_GetFitPoint()<br/>&nbsp;&nbsp;&nbsp; ' This example selects a spline object in model space.<br/>&nbsp;&nbsp;&nbsp; ' It then finds the coordinates of the fit points.</p><p>&nbsp;&nbsp;&nbsp; ' select the spline<br/>&nbsp;&nbsp;&nbsp; ' 创建新的选择集</p><p>&nbsp;&nbsp;&nbsp; Dim ssetObj As AcadSelectionSet<br/>&nbsp;&nbsp;&nbsp; 'Dim splineObj As AcadSpline</p><p><br/>&nbsp;&nbsp;&nbsp; Set ssetObj = ThisDrawing.SelectionSets.Add("SSpline")<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; '构建过滤器<br/>&nbsp;&nbsp;&nbsp; Dim fType As Variant, fData As Variant<br/>&nbsp;&nbsp;&nbsp; Call CreateSSetFilter(fType, fData, 0, "Spline")</p><p><br/>&nbsp;&nbsp;&nbsp; ' 提示用户选择样条曲线对象并将它们添加到选择集中。</p><p>&nbsp;&nbsp;&nbsp; ' 要完成选择,按回车。<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ssetObj.SelectOnScreen fType, fData</p><p>&nbsp;&nbsp;&nbsp; ZoomAll<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' Display the coordinates of the fit points<br/>&nbsp;&nbsp;&nbsp; Dim fitPoint As Variant<br/>&nbsp;&nbsp;&nbsp; Dim index As Integer<br/>&nbsp;&nbsp;&nbsp; For index = 0 To ssetObj.NumberOfFitPoints - 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fitPoint = ssetObj.GetFitPoint(index)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "Fit point " &amp; index + 1 &amp; " is at " &amp; fitPoint(0) &amp; ", " &amp; fitPoint(1) &amp; ", " &amp; fitPoint(2), , "GetFitPoint Example"<br/>&nbsp;&nbsp;&nbsp; Next<br/>&nbsp;&nbsp;&nbsp; <br/>End Sub<br/>' 创建选择集过滤器<br/>Public Sub CreateSSetFilter(ByRef filterType As Variant, ByRef filterData As Variant, ParamArray filter())<br/>&nbsp;&nbsp;&nbsp; If UBound(filter) Mod 2 = 0 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "filter参数无效!"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub<br/>&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Dim fType() As Integer&nbsp; ' 过滤器规则<br/>&nbsp;&nbsp;&nbsp; Dim fData() As Variant&nbsp; ' 过滤器参数<br/>&nbsp;&nbsp;&nbsp; Dim count As Integer<br/>&nbsp;&nbsp;&nbsp; count = (UBound(filter) + 1) / 2<br/>&nbsp;&nbsp;&nbsp; ReDim fType(count - 1)<br/>&nbsp;&nbsp;&nbsp; ReDim fData(count - 1)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Dim i As Integer<br/>&nbsp;&nbsp;&nbsp; For i = 0 To count - 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fType(i) = filter(2 * i)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fData(i) = filter(2 * i + 1)<br/>&nbsp;&nbsp;&nbsp; Next i<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; filterType = fType<br/>&nbsp;&nbsp;&nbsp; filterData = fData<br/>End Sub</p><p>调试发现ssetObj对象不能调用GetFitPoint()这个方法,请问应该怎么改代码呢?谢谢!</p>

alin 发表于 2007-10-16 11:49:00

<p>....</p><p>&nbsp;&nbsp;&nbsp; For i = 0 To ssetObj.count - 1<br/>&nbsp;&nbsp;&nbsp; For index = 0 To ssetObj(i).NumberOfFitPoints - 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fitPoint = ssetObj(i).GetFitPoint(index)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "Fit point " &amp; index + 1 &amp; " is at " &amp; fitPoint(0) &amp; ", " &amp; fitPoint(1) &amp; ", " &amp; fitPoint(2), , "GetFitPoint Example"<br/>&nbsp;&nbsp;&nbsp; Next<br/>&nbsp;&nbsp;&nbsp; Next</p><p>....</p>
页: [1]
查看完整版本: [求助]关于获取样条曲线的拟合点问题(附代码)