明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1492|回复: 1

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

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

大侠们好!我现在已有一张CAD图,想通过VBA实现获取里面的所有样条曲线的拟合点的坐标,我的代码如下:

Sub Select_GetFitPoint()
    ' This example selects a spline object in model space.
    ' It then finds the coordinates of the fit points.

    ' select the spline
    ' 创建新的选择集

    Dim ssetObj As AcadSelectionSet
    'Dim splineObj As AcadSpline


    Set ssetObj = ThisDrawing.SelectionSets.Add("SSpline")
   
    '构建过滤器
    Dim fType As Variant, fData As Variant
    Call CreateSSetFilter(fType, fData, 0, "Spline")


    ' 提示用户选择样条曲线对象并将它们添加到选择集中。

    ' 要完成选择,按回车。
   
    ssetObj.SelectOnScreen fType, fData

    ZoomAll
   
    ' Display the coordinates of the fit points
    Dim fitPoint As Variant
    Dim index As Integer
    For index = 0 To ssetObj.NumberOfFitPoints - 1
        fitPoint = ssetObj.GetFitPoint(index)
        MsgBox "Fit point " & index + 1 & " is at " & fitPoint(0) & ", " & fitPoint(1) & ", " & fitPoint(2), , "GetFitPoint Example"
    Next
   
End Sub
' 创建选择集过滤器
Public Sub CreateSSetFilter(ByRef filterType As Variant, ByRef filterData As Variant, ParamArray filter())
    If UBound(filter) Mod 2 = 0 Then
        MsgBox "filter参数无效!"
        Exit Sub
    End If
   
    Dim fType() As Integer  ' 过滤器规则
    Dim fData() As Variant  ' 过滤器参数
    Dim count As Integer
    count = (UBound(filter) + 1) / 2
    ReDim fType(count - 1)
    ReDim fData(count - 1)
   
    Dim i As Integer
    For i = 0 To count - 1
        fType(i) = filter(2 * i)
        fData(i) = filter(2 * i + 1)
    Next i
   
    filterType = fType
    filterData = fData
End Sub

调试发现ssetObj对象不能调用GetFitPoint()这个方法,请问应该怎么改代码呢?谢谢!

发表于 2007-10-16 11:49:00 | 显示全部楼层

....

    For i = 0 To ssetObj.count - 1
    For index = 0 To ssetObj(i).NumberOfFitPoints - 1
        fitPoint = ssetObj(i).GetFitPoint(index)
        MsgBox "Fit point " & index + 1 & " is at " & fitPoint(0) & ", " & fitPoint(1) & ", " & fitPoint(2), , "GetFitPoint Example"
    Next
    Next

....

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-26 12:21 , Processed in 0.167038 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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