The code in one of my previous posts actually does have an issue. It does not take the base point of the block definition into account. Gile's code does.
My improved and cleaned up code:
;;; 20140613
;;; Get a matrix from an insert.
;;; See: http://www.theswamp.org/index.php?topic=47227.0
;;; (equal (KGA_Geom_MatrixMakeInsert (car (entsel))) (caddr (nentselp)) 1e-8)
(defun KGA_Geom_MatrixMakeInsert (ename / ang elist normal xVector yVector zVector)
(setq elist (entget ename))
(setq normal (cdr (assoc 210 elist)))
(setq ang (cdr (assoc 50 elist)))
(KGA_Geom_MatrixMake
(setq xVector (KGA_Geom_VectorScale (trans (list (cos ang) (sin ang) 0.0) normal 0 T) (cdr (assoc 41 elist))))
(setq yVector (KGA_Geom_VectorScale (trans (list (- (sin ang)) (cos ang) 0.0) normal 0 T) (cdr (assoc 42 elist))))
(setq zVector (KGA_Geom_VectorScale (trans '(0.0 0.0 1.0) normal 0 T) (cdr (assoc 43 elist))))
(mapcar
'-
(trans (cdr (assoc 10 elist)) normal 0) ; Origin (insertion point).
(mapcar
'(lambda (lst) (apply '+ lst))
(KGA_Geom_MatrixTranspose
(mapcar
'KGA_Geom_VectorScale
(list xVector yVector zVector)
(cdr (assoc 10 (tblsearch "block" (cdr (assoc 2 elist))))) ; Base point of the block definition.
)
)
)
)
)
)
;;; 20140613: Revised. See (KGA_Geom_MatrixTranspose).
;;; 20120201
;;; Get a 4x4 matrix from three vectors and an origin.
(defun KGA_Geom_MatrixMake (xVector yVector zVector origin)
(append
(mapcar 'list xVector yVector zVector origin)
'((0.0 0.0 0.0 1.0))
)
)
;;; 20140613
;;; Transpose a matrix.
;;; By Doug Wilson (via gile, www.theswamp.org). Original name 'trp'.
(defun KGA_Geom_MatrixTranspose (matrix)
(apply 'mapcar (cons 'list matrix))
)
; 20120201
; (KGA_Geom_VectorScale '(1 2 3) 3) => (3.0 6.0 9.0)
(defun KGA_Geom_VectorScale (vector scalar)
(mapcar '(lambda (a) (* a (float scalar))) vector)
)