明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1787|回复: 2

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

[复制链接]
发表于 2006-9-18 20:43:00 | 显示全部楼层 |阅读模式
本帖最后由 作者 于 2006-9-19 14:39:20 编辑

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

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

本版积分规则

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

GMT+8, 2024-11-26 22:17 , Processed in 0.169293 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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