ActiveUCS Property (ActiveX)

Specifies the active UCS for the drawing.

Supported platforms: Windows only

Signature

VBA:

object.ActiveUCS
object

Type: Document

The object this property applies to.

Property Value

Read-only: No

Type: UCS

The active UCS for the drawing.

Remarks

Changes made to the current active UCS will become visible only after that UCS is reset as the active UCS.

If you try to get the active UCS value when the current UCS is unsaved, an error will occur. It is recommended that you confirm that the value of the UCSNAME system variable is not empty before you get the active UCS value. Alternatively, you can add a new UCS object and set it to active before getting the active UCS value.

Examples

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)))
)