TransformBy Method (ActiveX)

Moves, scales, or rotates an object given a 4x4 transformation matrix.

Supported platforms: Windows only

Signature

VBA:

object.TransformBy TransformationMatrix
object

Type: All drawing objects, AttributeReference

The object this method applies to.

TransformationMatrix

Access: Input-only

Type: Variant (4x4 array of doubles)

A 4x4 matrix specifying the transformation to perform.

Return Value (RetVal)

No return value.

Remarks

The following table demonstrates the transformation matrix configuration, where R = Rotation, and T = Translation: R00

R00 R01 R02 T0
R10 R11 R12 T1
R20 R21 R22 T2
0 0 0 1

This method will return an error if the transformation matrix is not correct.

Sample transformation matrices are provided in the example code for this method.

Examples

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

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