図面のアクティブな UCS を指定します。
サポートされているプラットフォーム: Windows のみ
現在のアクティブな UCS への変更は、UCS がアクティブな UCS としてリセットされた後にのみ反映されます。
現在の UCS が保存されていない場合にアクティブな UCS を取得しようとすると、エラーが発生します。アクティブな UCS 値を取得する前に、UCSNAME システム変数の値が空でないことを確認することをお勧めします。または、新しい UCS オブジェクトを追加し、それをアクティブにしてからアクティブな UCS 値を取得することもできます。
VBA:
Sub Example_ActiveUCS()
' 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
' 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
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
Visual LISP:
(vl-load-com)
(defun c:Example_ActiveUCS()
;; 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.
(setq acadObj (vlax-get-acad-object))
(setq doc (vla-get-ActiveDocument acadObj))
(setq UCSs (vla-get-UserCoordinateSystems doc))
;; 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 (= (vlax-variant-value (vla-GetVariable doc "UCSNAME")) "")
(progn
(setq utility (vla-get-Utility doc))
(setq currUCS (vla-Add UCSs
(vla-GetVariable doc "UCSORG")
(vla-TranslateCoordinates utility (vla-GetVariable doc "UCSXDIR") acUCS acWorld :vlax-false)
(vla-TranslateCoordinates utility (vla-GetVariable doc "UCSYDIR") acUCS acWorld :vlax-false)
"OriginalUCS"
)
)
)
(setq currUCS (vla-get-ActiveUCS doc)) ;; current UCS is saved
)
(alert (strcat "The current UCS is " (vla-get-Name currUCS)))
;; Create a UCS and make it current
(setq origin (vlax-3d-point 0 0 0)
xAxis (vlax-3d-point 1 1 0)
yAxis (vlax-3d-point -1 1 0))
(setq newUCS (vla-Add UCSs origin xAxis yAxis "TestUCS"))
(vla-put-ActiveUCS doc newUCS)
(alert (strcat "The new UCS is " (vla-get-Name newUCS)))
;; Restore the previous UCS
(vla-put-ActiveUCS doc currUCS)
(alert (strcat "The UCS is restored to " (vla-get-Name currUCS)))
)