唐僧肉 发表于 2006-9-18 20:43:00

[VBA]如何得到当前文档的当前无名ucs的转换矩阵?

rt

唐僧肉 发表于 2006-9-19 11:17:00

autodesk的代码如下,按照原理应该可行,可惜坐标转换之后保存的OriginalUCS有错误。郁闷啊。
Sub Example_ActiveUCS1()
    ' This example returns the current saved UCS (or saves a new one dynamically)
    ' and then sets a new UCS.
    ' Finally, it returns the UCS to the previous setting.
   
    Dim newUCS As AcadUCS
    Dim currUCS As AcadUCS
    Dim origin(0 To 2) As Double
    Dim xAxis(0 To 2) As Double
    Dim yAxis(0 To 2) As Double
    Dim pnt As Variant
    ' Get the current saved UCS of the active document. If the current UCS is
    ' not saved, then add a new UCS to the UserCoordinateSystems collection
    If ThisDrawing.GetVariable("UCSNAME") = "" Then
      ' Current UCS is not saved so get the data and save it
      With ThisDrawing
            Set currUCS = .UserCoordinateSystems.Add( _
                            .GetVariable("UCSORG"), _
                            .Utility.TranslateCoordinates(.GetVariable("UCSXDIR"), acUCS, acWorld, 0), _
                            .Utility.TranslateCoordinates(.GetVariable("UCSYDIR"), acUCS, acWorld, 0), _
                            "OriginalUCS")
      End With
    Else
      Set currUCS = ThisDrawing.ActiveUCS'current UCS is saved
    End If
'                            .Utility.TranslateCoordinates(.GetVariable("UCSXDIR"), acUCS, acWorld, 0), _
'                            .Utility.TranslateCoordinates(.GetVariable("UCSYDIR"), acUCS, acWorld, 0), _
                           
'
pnt = ThisDrawing.GetVariable("UCSORG")
    Debug.Print pnt(0); pnt(1); pnt(2)
    pnt = ThisDrawing.GetVariable("UCSXDIR")
    Debug.Print pnt(0); pnt(1); pnt(2)
    pnt = ThisDrawing.GetVariable("UCSYDIR")
    Debug.Print pnt(0); pnt(1); pnt(2)
   
    pnt = ThisDrawing.Utility.TranslateCoordinates(ThisDrawing.GetVariable("UCSXDIR"), acUCS, acWorld, 0)
    Debug.Print pnt(0); pnt(1); pnt(2)
   
    pnt = ThisDrawing.Utility.TranslateCoordinates(ThisDrawing.GetVariable("UCSYDIR"), acUCS, acWorld, 0)
    Debug.Print pnt(0); pnt(1); pnt(2)
   


    MsgBox "The current UCS is " & currUCS.Name, vbInformation, "ActiveUCS Example"
    ' Create a UCS and make it current
    origin(0) = 0: origin(1) = 0: origin(2) = 0
    xAxis(0) = 1: xAxis(1) = 1: xAxis(2) = 0
    yAxis(0) = -1: yAxis(1) = 1: yAxis(2) = 0
    Set newUCS = ThisDrawing.UserCoordinateSystems.Add(origin, xAxis, yAxis, "TestUCS")
    ThisDrawing.ActiveUCS = newUCS
    MsgBox "The new UCS is " & newUCS.Name, vbInformation, "ActiveUCS Example"
    ' Reset the UCS to its previous setting
    ThisDrawing.ActiveUCS = currUCS
    MsgBox "The UCS is reset to " & currUCS.Name, vbInformation, "ActiveUCS Example"
End Sub


唐僧肉 发表于 2006-9-19 14:19:00

这样就好了。呵呵。小心autodesk蒙人。

    If ThisDrawing.GetVariable("UCSNAME") = "" Then
      ' Current UCS is not saved so get the data and save it   '.GetVariable("UCSORG"),
      With ThisDrawing
            Set currUCS = .UserCoordinateSystems.Add( _
                            pnt1, _
                            .GetVariable("UCSXDIR"), _
                            .GetVariable("UCSYDIR"), _
                            "OriginalUCS")
                            currUCS.origin = .GetVariable("UCSORG")
      End With
    Else
      Set currUCS = ThisDrawing.ActiveUCS'current UCS is saved
    End If
页: [1]
查看完整版本: [VBA]如何得到当前文档的当前无名ucs的转换矩阵?