Lisp: Put all XREFs on layer "
I need a lisp routine to put all xrefs in a drawing onto the layer "G-XREF". Where;If the layer does not exist it would be created first?
?
:unsure: (defun c:XRL (/ objs ent i)(setq objs (ssget "_X" '((0 . "INSERT")(8 . "~G-XREF"))))(repeat (setq i (sslength objs)) (setq ent (entget (ssname objs (setq i (1- i))))) (if (and (= 4 (logand 4 (cdr (assoc 70 (tblsearch "BLOCK" (cdr (assoc 2 ent))))))) (= (cdr (assoc 70 (entget (tblobjname "LAYER" (cdr (assoc 8 ent)))))) 0)) (entmod (subst (cons 8 "G-XREF")(assoc 8 ent) ent)))))
You may need also to add some more codes for adding the layer name to the layer Name list pBe.
No tharwat, entmod does that for you.
if the layer does not exist it will create the layer on the fly
What should be added is a filter excluding INSERTS/XREF already on layer G-XREF
(setq objs (ssget "_X" '((0 . "INSERT")(8 . "~G-XREF")))) You're right pBe .
I am sorry for the confusion .
No worries Tharwat. and again no need to apologize my friend.
Cheers
Nice one pBe; just be sure to watch for XREF's on locked layers :wink:
Thanks Renderman.
Your are right
Post updated Building on your code, and just for fun:
(defun c:XRL2 ( / ss l) (if (setq ss (ssget "_x" (list '(0 . "INSERT") (cons 8 (strcat "~" (setq l "G-XREF")))))) ((lambda (i / e n) (while (setq e (entget (ssname ss (setq i (1+ i))))) (if (and (= 4 (logand 4 (cdr (assoc 70 (tblsearch "block" (cdr (assoc 2 e))))))) (= 0 (cdr (assoc 70 (entget (tblobjname "layer" (cdr (setq n (assoc 8 e))))))))) (entmod (subst (cons 8 l) n e))))) -1) (prompt "\n** Nothing selected ** ")) (princ))
(defun c:XRL3 ( / dxf ss l) (defun dxf (n eData) (if (and (= 'INT (type n)) (listp eData)) (cdr (assoc n eData)) (prompt "\n** \"DXF\" error: Invalid argument ** ")))(if (setq ss (ssget "_x" (list '(0 . "INSERT") (cons 8 (strcat "~" (setq l "G-XREF")))))) ((lambda (i / e) (while (setq e (entget (ssname ss (setq i (1+ i))))) (if (and (= 4 (logand 4 (dxf 70 (tblsearch "block" (dxf 2 e))))) (= 0 (dxf 70 (entget (tblobjname "layer" (dxf 8 e)))))) (entmod (subst (cons 8 l) (assoc 8 e) e))))) -1) (prompt "\n** Nothing selected ** ")) (princ)) Great stuff Renderman.
Question for you.
Canyou use both "_X" and":L" method of selection for ssget together in one syntax? perhaps on newer version?
页:
[1]
2