TransformBy 方法 (ActiveX)
移动、缩放或旋转给定 4x4 变换矩阵的对象。 支持的平台:仅限 Windows 签名VBA: object.TransformBy TransformationMatrix
返回值 (RetVal)无返回值。 言论下表演示了转换矩阵配置,其中 R = 旋转,T = 平移:R00
如果转换矩阵不正确,此方法将返回错误。 此方法的示例代码中提供了示例转换矩阵。 例子VBA: Sub Example_TransformBy()
' This example creates a line and rotates it 90 degrees
' using a transformation matrix.
' Create a line
Dim lineObj As AcadLine
Dim startPt(0 To 2) As Double
Dim endPt(0 To 2) As Double
startPt(0) = 2: startPt(1) = 1: startPt(2) = 0
endPt(0) = 5: endPt(1) = 1: endPt(2) = 0
Set lineObj = ThisDrawing.ModelSpace.AddLine(startPt, endPt)
lineObj.Update
' Initialize the transMat variable with a transformation matrix
' that will rotate an object by 90 degrees about the point(0,0,0)
' (More examples of transformation matrices are listed below)
Dim transMat(0 To 3, 0 To 3) As Double
transMat(0, 0) = 0#: transMat(0, 1) = -1#: transMat(0, 2) = 0#: transMat(0, 3) = 0#
transMat(1, 0) = 1#: transMat(1, 1) = 0#: transMat(1, 2) = 0#: transMat(1, 3) = 0#
transMat(2, 0) = 0#: transMat(2, 1) = 0#: transMat(2, 2) = 1#: transMat(2, 3) = 0#
transMat(3, 0) = 0#: transMat(3, 1) = 0#: transMat(3, 2) = 0#: transMat(3, 3) = 1#
' Transform the line using the defined transformation matrix
MsgBox "Transform the line.", , "TransformBy Example"
lineObj.TransformBy (transMat)
ZoomAll
MsgBox "The line is transformed.", , "TransformBy Example"
' More examples of transformation matrices:
' Rotation Matrix: 90 Degrees about point 0,0,0
' 0.000000 -1.000000 0.000000 0.000000
' 1.000000 0.000000 0.000000 0.000000
' 0.000000 0.000000 1.000000 0.000000
' 0.000000 0.000000 0.000000 1.000000
' Rotation Matrix: 45 Degrees about point 5,5,0
' 0.70710678118654 -0.70710678118654 0.000000 5.000000
' 0.70710678118654 0.70710678118654 0.000000 -2.071068
' 0.000000 0.000000 1.000000 0.000000
' 0.000000 0.000000 0.000000 1.000000
' Translation Matrix: move an object by 10,10,0
' 1.000000 0.000000 0.000000 10.000000
' 0.000000 1.000000 0.000000 10.000000
' 0.000000 0.000000 1.000000 0.000000
' 0.000000 0.000000 0.000000 1.000000
' Scaling Matrix: scale by 10,10 at point 0,0,0
' 10.000000 0.000000 0.000000 0.000000
' 0.000000 10.000000 0.000000 0.000000
' 0.000000 0.000000 10.000000 0.000000
' 0.000000 0.000000 0.000000 1.000000
' Scaling Matrix: scale by 10 at point 2,2
' 10.000000 0.000000 0.000000 -18.000000
' 0.000000 10.000000 0.000000 -18.000000
' 0.000000 0.000000 10.000000 0.000000
' 0.000000 0.000000 0.000000 1.000000
End Sub
可视化 LISP: (vl-load-com)
(defun c:Example_TransformBy()
;; This example creates a line and rotates it 90 degrees
;; using a transformation matrix.
(setq acadObj (vlax-get-acad-object))
(setq doc (vla-get-ActiveDocument acadObj))
;; Create a line
(setq startPt (vlax-3d-point 2 1 0)
endPt (vlax-3d-point 5 1 0))
(setq modelSpace (vla-get-ModelSpace doc))
(setq lineObj (vla-AddLine modelSpace startPt endPt))
(vla-Update lineObj)
;; Initialize the transMat variable with a transformation matrix
;; that will rotate an object by 90 degrees about the point(0,0,0)
;; (More examples of transformation matrices are listed below)
(setq transMat (vlax-tmatrix '((0 -1 0 0)
(1 0 0 0)
(0 0 1 0)
(0 0 0 1))))
;; Transform the line using the defined transformation matrix
(alert "Transform the line.")
(vla-TransformBy lineObj transMat)
(vla-ZoomAll acadObj)
(vla-Regen doc acAllViewports)
(alert "The line is transformed.")
;; More examples of transformation matrices:
;; Rotation Matrix: 90 Degrees about point 0,0,0
; (setq transMat (vlax-tmatrix '((0 -1 0 0)
; (1 0 0 0)
; (0 0 1 0)
; (0 0 0 1))))
;; Rotation Matrix: 45 Degrees about point 5,5,0
; (setq transMat (vlax-tmatrix '((0.70710678118654 -0.70710678118654 0 5)
; (0.70710678118654 0.70710678118654 0 -2.071068)
; (0 0 1 0)
; (0 0 0 1))))
;; Translation Matrix: move an object by 10,10,0
; (setq transMat (vlax-tmatrix '((1 0 0 10)
; (0 1 0 10)
; (0 0 1 0)
; (0 0 0 1))))
;; Scaling Matrix: scale by 10,10 at point 0,0,0
; (setq transMat (vlax-tmatrix '((10 0 0 0)
; (0 10 0 0)
; (0 0 10 0)
; (0 0 0 1))))
;; Scaling Matrix: scale by 10 at point 2,2
; (setq transMat (vlax-tmatrix '((10 0 0 -18)
; (0 10 0 -18)
; (0 0 10 0)
; (0 0 0 1))))
)
|
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-10-29 20:18
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.