Code Red > AutoLISP (Vanilla / Visual)
finding nested xrefs - AutoLISP
jbuzbee:
I have a routine that "backs up" files. It works fine but I need find out which xrefs are nested.
Thanks for any help
ronjonp:
Maybe this? http://www.theswamp.org/index.php?topic=25196.msg303571#msg303571
jbuzbee:
This looks like a good start - Thanks!
Lee Mac:
Below is a variation of the code I previously posted here, modified to apply to xrefs only:
--- Code - Auto/Visual Lisp: ---(defun _nestedxrefs ( blk / enx rtn xrn ) (while (setq blk (entnext blk)) (if (and (setq enx (entget blk)) (= "INSERT" (cdr (assoc 0 enx))) (setq xrn (cdr (assoc 2 enx))) (= 4 (logand 4 (cdr (assoc 70 (tblsearch "block" xrn))))) (not (member xrn rtn)) ) (setq rtn (cons xrn rtn)) ) ) rtn)(defun _xrefhierarchy ( / blk def nst rtn ) (while (setq def (tblnext "block" (null def))) (if (or (setq blk (cdr (assoc 2 def)) nst (_nestedxrefs (tblobjname "block" blk)) ) (= 4 (logand 4 (cdr (assoc 70 def)))) ) (setq rtn (cons (cons blk nst) rtn)) ) ) rtn)(defun _printxrefhierarchy ( blk lst ind ) (terpri) (repeat ind (princ " ")) (princ "+---") (if (setq nst (cdr (assoc blk lst))) (progn (princ "+ ") (princ blk) (foreach sub nst (_printxrefhierarchy sub lst (1+ ind)) ) ) (progn (princ "> ") (princ blk) ) ))(defun c:xrefhierarchy ( ) ( (lambda ( lst ) (foreach blk lst (_printxrefhierarchy (car blk) lst 0) ) (textpage) ) (_xrefhierarchy) ) (princ))
Lee Mac:
Alternatively, here's a predicate function that will return T if the supplied block name corresponds to a nested xref:
--- Code - Auto/Visual Lisp: ---(defun nestedxref-p ( xrn / def ent enx flg tmp ) (and (setq def (tblsearch "block" (setq xrn (strcase xrn)))) (= 4 (logand 4 (cdr (assoc 70 def)))) (progn (while (and (setq tmp (tblnext "block" (not tmp))) (not flg) ) (setq ent (tblobjname "block" (cdr (assoc 2 tmp)))) (while (and (setq ent (entnext ent)) (not flg) ) (setq flg (and (setq enx (entget ent)) (= "INSERT" (cdr (assoc 0 enx))) (= xrn (strcase (cdr (assoc 2 enx)))) ) ) ) ) flg ) ))
--- Code - Auto/Visual Lisp: ---(nestedxref-p "YourXRefName")
Navigation
[0] Message Index
[#] Next page
Go to full version