Hi,
I'm going to try to explain the way I do in spite of my poor English.
First, get the entity using nentsel
nentsel returns a list wich:
1st item is the object ename
2nd item the pick point coordinates (UCS)
3rd item a 4X3 transformation matrix
4th item a list of references enames from the most nested (the entity owner) to the less one.
(setq ent (nentsel))
(setq ename (car ent)) ;ename of nested selected entity
(setq owner (car (last ent))) ;ename of the entity owner
(setq mat (reverse (cdr (reverse (caddr ent))))) ; 3X3 tranformation matrix
(setq ins (last (caddr ent))) ; insertion point of the owner
(setq coord (cdr (assoc 10 (entget ename)))) ; entity coordinates in its owner definition
The transformation matrix returned by nentsel can be splited in a 3X3 rotation and scaling matrix and a displacement vector (matrix last row).
The 3X3 matrix corresponds to the transformation from the reference insertion (including rotations and X,Y,Z scalings) to the block definition.
The vector corresponds to the displacement from WCS origin to the insertion point of the owner of selected entity.
So, we can transform the "original" entity coordinates to its "transformed" coordinates in the reference by applaying them the transposed 3X3 matrix and and displace ithem with the displacement vector.
To do this I use 2 little routines mxv and trp.
;; transpose une matrice by Doug Wilson
(defun trp (m)
(apply 'mapcar (cons 'list m))
)
;; Apply a transformation matrix to a vector by Vladimir Nesterovsky
(defun mxv (m v)
(mapcar (function (lambda (r) (vxv r v))) m)
)
(setq WCScoord (mapcar '+ ins (mxv (trp mat) coord)))
Hope it helps.