明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1268|回复: 0

[求助]请教此代码为何不能得到样条曲线拟合点的UCS坐标值,而只能得到其WCS坐标值?

[复制链接]
发表于 2007-10-16 21:26:00 | 显示全部楼层 |阅读模式
[求助]请教此代码为何不能得到样条曲线拟合点的UCS坐标值,而只能得到其WCS坐标值?谢谢[br]

Sub test_AddOrgUCS()
    '原点UCS调用示例
    Dim myUCS As AcadUCS, NewOrgPt As Variant
    NewOrgPt = ThisDrawing.Utility.GetPoint(, vbCrLf & "请输入新原点:")
    Set myUCS = AddOrgUCS(NewOrgPt, "abc")
    ThisDrawing.ActiveUCS = myUCS
     ' This example selects a spline object in model space.
    ' It then finds the coordinates of the fit points.

    Dim ssetObj As AcadSelectionSet

    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 i = 0 To ssetObj.count - 1
    For index = 0 To ssetObj(i).NumberOfFitPoints - 1
        fitPoint = ssetObj(i).GetFitPoint(index)
        MsgBox "拟合点" & index + 1 & " 的坐标为: " & fitPoint(0) & ", " & fitPoint(1) & ", " & fitPoint(2), , "GetFitPoint Example"
    Next
    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

' 移动原点创建UCS
' ptOriginWcs:新UCS的原点在WCS中的坐标
Public Function AddOrgUCS(ptOriginWcs As Variant, strUcsName As String) As AcadUCS
    ' 获得新UCS原点在当前UCS中的坐标
    Dim ptOriginUcs As Variant
    ptOriginUcs = PtWcs2Ucs(ptOriginWcs)
    'Debug.Print ptOriginWcs(0)
    ' 获得X、Y正半轴上任一点的UCS坐标
    Dim ptXUcs(0 To 2) As Double, ptYUcs(0 To 2) As Double
    ptXUcs(0) = ptOriginUcs(0) + 1
    ptXUcs(1) = ptOriginUcs(1)
    ptXUcs(2) = ptOriginUcs(2)
    ptYUcs(0) = ptOriginUcs(0)
    ptYUcs(1) = ptOriginUcs(1) + 1
    ptYUcs(2) = ptOriginUcs(2)
   
    ' 获得X、Y正半轴上任一点的WCS坐标
    Dim ptXWcs As Variant, ptYWcs As Variant
    ptOriginWcs = PtUcs2Wcs(ptOriginUcs)
    ptXWcs = PtUcs2Wcs(ptXUcs)
    ptYWcs = PtUcs2Wcs(ptYUcs)
    'Debug.Print ptOriginWcs(0)
    ' 创建UCS
    Set AddOrgUCS = ThisDrawing.UserCoordinateSystems.Add(ptOriginWcs, ptXWcs, ptYWcs, strUcsName)
End Function

' 将点的UCS坐标转化到WCS坐标
Private Function PtUcs2Wcs(ptUcs As Variant) As Variant
    PtUcs2Wcs = ThisDrawing.Utility.TranslateCoordinates(ptUcs, acUCS, acWorld, False)
End Function

' 将点的WCS坐标转化到UCS坐标
Private Function PtWcs2Ucs(ptWcs As Variant) As Variant
    PtWcs2Ucs = ThisDrawing.Utility.TranslateCoordinates(ptWcs, acWorld, acUCS, False)
End Function

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

本版积分规则

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

GMT+8, 2024-11-26 12:38 , Processed in 0.212419 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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