Funny that you pick an example with all the base points at 0,0,0 .
I wrote an getInsertionPoint function to find all the nested points.
Its a recursive function that transforms the points each time it is nested.
That way in the end you should get the absolute coordinates of the blocks insertion point.
It returns a list with all the block names it is nested in so you can find the one you want.
Code:
(defun c:test (/ ent)
(setq ent (car (entsel)))
(setq insertionPoints (getInsertionPoints nil ent)) ; Get insertion points
(foreach pnt insertionPoints ; Draw them to show that is works
(entmakex (list '(0 . "POINT") (cons 10 (cadr pnt))))
)
insertionPoints ; Return info
)
(defun getInsertionPoints (prefix ent / blockName ent enx mat nestedBlocks thisBlock)
(setq enx (entget ent))
(setq blockName (cdr (assoc 2 enx))) ; Block Name
(setq mat (Mat:refgeom ent)) ; Transfromation matrix for this block
(setq thisBlock ; Insertion Point for this block
(list
(cond (prefix (strcat prefix ":" blockName)) (blockName)) ; Block name with prefix
(trans (cdr (assoc 10 enx)) (cdr (assoc 210 enx)) 0) ; Insertion Point
)
)
(if (setq ent (tblobjname "BLOCK" blockName))
(while (and ent (setq ent (entnext ent))) ; loop though items inside block
(if (= (cdr (assoc 0 (entget ent))) "INSERT") ; If a nested block is found
(progn
(setq nestedBlocks
(mapcar
(function
(lambda (blk) ; Go through items retuned from getInsertionPoints
(list
(car blk) ; Keep block name the same
(mapcar '+ (Mat:mxv (car mat) (cadr blk)) '(0 0 0) (cadr mat)) ; Transform with refgeom matrix
)
)
)
(getInsertionPoints (car thisBlock) ent) ; Go deeper
)
)
)
)
)
)
(cons thisBlock nestedblocks)
)
;;;-----------------------------------------------------------------------------;;
;;; RefGeom - gile ;;
;;; Returns a list whose first item is a 3x3 transformation matrix and ;;
;;; second item the object insertion point in its parent (xref, block or space) ;;
;;;-----------------------------------------------------------------------------;;
(defun Mat:refgeom (ent / ang enx mat ocs)
(setq enx (entget ent)
ang (cdr (assoc 050 enx))
ocs (cdr (assoc 210 enx)))
(list
(setq mat
(Mat:mxm
(mapcar
(function (lambda (v) (trans v 0 ocs t)))
'(
(1.0 0.0 0.0)
(0.0 1.0 0.0)
(0.0 0.0 1.0)
)
)
(Mat:mxm
(list
(list (cos ang) (- (sin ang)) 0.0)
(list (sin ang) (cos ang) 0.0)
'(0.0 0.0 1.0)
)
(list
(list (cdr (assoc 41 enx)) 0.0 0.0)
(list 0.0 (cdr (assoc 42 enx)) 0.0)
(list 0.0 0.0 (cdr (assoc 43 enx)))
)
)
)
)
(mapcar '-
(trans (cdr (assoc 10 enx)) ocs 0)
(Mat:mxv mat (cdr (assoc 10 (tblsearch "block" (cdr (assoc 2 enx))))))
)
)
)
;;;-----------------------------------------------------------;;
;;; Matrix x Vector - Vladimir Nesterovsky ;;
;;; Args: m - nxn matrix, v - vector in R^n ;;
;;;-----------------------------------------------------------;;
(defun Mat:mxv (m v)
(mapcar (function (lambda (r) (apply '+ (mapcar '* r v)))) m)
)
;;;-----------------------------------------------------------;;
;;; Matrix x Matrix - Vladimir Nesterovsky ;;
;;; Args: m,n - nxn matrices ;;
;;;-----------------------------------------------------------;;
(defun Mat:mxm (m n)
((lambda (a) (mapcar (function (lambda (r) (Mat:mxv a r))) m)) (Mat:trp n))
)
;;;-----------------------------------------------------------;;
;;; Matrix Transpose - Doug Wilson ;;
;;; Args: m - nxn matrix ;;
;;;-----------------------------------------------------------;;
(defun Mat:trp (m)
(apply 'mapcar (cons 'list m))
)
(princ)
- - - Updated - - -
Originally Posted by
Ed Jobe
I understand, also editing posts doesn't work probably because of the same reason.
Guess I'll have to post more then