;;;从AutoCAD 2013 Active Reference帮助中code Examples中提取
;;;本源代码由 xshrimp 2013.2.20 搜集整理,版权归原作者所有!


(vl-load-com)
(defun c:Example_GetUCSMatrix()
    ;; This example creates a new UCS and finds the UCS matrix for it.
    ;; It then creates a circle using WCS coordinates and
    ;; transforms the circle for the UCS.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
  
    ;; Define a new UCS and turn on the UCS icon at the origin.
    (setq origin (vlax-3d-point 2 2 0)
          xAxisPoint (vlax-3d-point 3 2 0)
          yAxisPoint (vlax-3d-point 2 3 0))
    
    (setq ucsObj (vla-Add (vla-get-UserCoordinateSystems doc) origin xAxisPoint yAxisPoint "UCS1"))
    (vla-put-ActiveUCS doc ucsObj)
    (vla-put-UCSIconOn (vla-get-ActiveViewport doc) :vlax-true)
    (vla-put-UCSIconAtOrigin (vla-get-ActiveViewport doc) :vlax-true)
    (vla-put-ActiveViewport doc (vla-get-ActiveViewport doc))
    
    ;; Create a circle using WCS coordinates
    (setq center (vlax-3d-point 1 1 0)
          radius 0.5)
    (setq modelSpace (vla-get-ModelSpace doc))
    (setq circleObj (vla-AddCircle modelSpace center radius))
    (vla-ZoomAll acadObj)
    
    ;; Get the UCS transformation matrix
    (setq TransMatrix (vla-GetUCSMatrix ucsObj))
    
    ;; Transform the circle to the UCS coordinates
    (alert "Transform the circle.")
    (vla-TransformBy circleObj TransMatrix)
    (vla-Update circleObj)
    
    (alert "The circle is transformed.")
)