CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2025 开发者帮助

GetUCSMatrix 方法 (ActiveX)

2024-5-18 19:20| 发布者: admin| 查看: 105| 评论: 0|原作者: admin|来自: AutoCAD

GetUCSMatrix 方法 (ActiveX)

获取由 UCS 坐标系数据组成的变换矩阵。

支持的平台:仅限 Windows

签名

VBA:

RetVal = object.GetUCSMatrix()
对象

类型:UCS

此方法应用到的对象。

返回值 (RetVal)

类型:变体(4x4 双打阵列)

UCS 矩阵。

言论

若要将实体转换为给定的 UCS,请使用该方法,使用此方法返回的矩阵作为该方法的输入。TransformBy

例子

VBA:

Sub 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.
    
    ' Define a new UCS and turn on the UCS icon at the origin.
    Dim ucsObj As AcadUCS
    Dim origin(0 To 2) As Double
    Dim xAxisPoint(0 To 2) As Double
    Dim yAxisPoint(0 To 2) As Double
    
    origin(0) = 2: origin(1) = 2: origin(2) = 0
    xAxisPoint(0) = 3: xAxisPoint(1) = 2: xAxisPoint(2) = 0
    yAxisPoint(0) = 2: yAxisPoint(1) = 3: yAxisPoint(2) = 0
    
    Set ucsObj = ThisDrawing.UserCoordinateSystems.Add(origin, xAxisPoint, yAxisPoint, "UCS1")
    ThisDrawing.ActiveUCS = ucsObj
    ThisDrawing.ActiveViewport.UCSIconOn = True
    ThisDrawing.ActiveViewport.UCSIconAtOrigin = True
    ThisDrawing.ActiveViewport = ThisDrawing.ActiveViewport
    
    ' Create a circle using WCS coordinates
    Dim circleObj As AcadCircle
    Dim center(0 To 2) As Double
    Dim radius As Double
    center(0) = 1: center(1) = 1: center(2) = 0
    radius = 0.5
    Set circleObj = ThisDrawing.ModelSpace.AddCircle(center, radius)
    ZoomAll
    
    ' Get the UCS transformation matrix
    Dim TransMatrix As Variant
    TransMatrix = ucsObj.GetUCSMatrix()
    
    ' Transform the circle to the UCS coordinates
    MsgBox "Transform the circle.", , "GetUCSMatrix Example"
    circleObj.TransformBy (TransMatrix)
    circleObj.Update
    
    MsgBox "The circle is transformed.", , "GetUCSMatrix Example"
        
End Sub

可视化 LISP:

(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.")
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1   苏公网安备32011402011833)

GMT+8, 2024-12-15 22:30

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部