mrharris78 Posted September 19, 2011 Share Posted September 19, 2011 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: Quote Link to comment Share on other sites More sharing options...
pBe Posted September 19, 2011 Share Posted September 19, 2011 (edited) (defun c:XRL (/ objs ent i) (setq objs (ssget "_X" '((0 . "INSERT")[color=blue](8 . "~G-XREF")[/color]))) (repeat (setq i (sslength objs)) (setq ent (entget (ssname objs (setq i (1- i))))) (if [color=blue](and[/color] (= 4 (logand 4 (cdr (assoc 70 (tblsearch "BLOCK" (cdr (assoc 2 ent))))))) [color=blue](= (cdr (assoc 70 (entget (tblobjname "LAYER" (cdr (assoc 8 ent)))))) 0))[/color] (entmod (subst (cons 8 "G-XREF")(assoc 8 ent) ent)))) ) Edited September 20, 2011 by pBe Add layer locked cond Quote Link to comment Share on other sites More sharing options...
Tharwat Posted September 19, 2011 Share Posted September 19, 2011 If the layer does not exist it would be created first? : You may need also to add some more codes for adding the layer name to the layer Name list pBe. Quote Link to comment Share on other sites More sharing options...
pBe Posted September 19, 2011 Share Posted September 19, 2011 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")[color=blue](8 . "~G-XREF")[/color]))) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted September 19, 2011 Share Posted September 19, 2011 You're right pBe . I am sorry for the confusion . Quote Link to comment Share on other sites More sharing options...
pBe Posted September 19, 2011 Share Posted September 19, 2011 You're right pBe . I am sorry for the confusion . No worries Tharwat. and again no need to apologize my friend. Cheers Quote Link to comment Share on other sites More sharing options...
BlackBox Posted September 19, 2011 Share Posted September 19, 2011 (defun c:XRL (/ objs ent i) (setq objs (ssget "_X" '((0 . "INSERT")))) (repeat (setq i (sslength objs)) (setq ent (entget (ssname objs (setq i (1- i))))) (if (= 4 (logand 4 (cdr (assoc 70 (tblsearch "BLOCK" (cdr (assoc 2 ent))))))) (entmod (subst (cons 8 "G-XREF")(assoc 8 ent) ent)))) ) What should be added is a filter excluding INSERTS/XREF already on layer G-XREF (setq objs (ssget "_X" '((0 . "INSERT")[color=blue](8 . "~G-XREF")[/color]))) Nice one pBe; just be sure to watch for XREF's on locked layers :wink: Quote Link to comment Share on other sites More sharing options...
pBe Posted September 20, 2011 Share Posted September 20, 2011 Nice one pBe; just be sure to watch for XREF's on locked layers :wink: Thanks Renderman. Your are right Post updated Quote Link to comment Share on other sites More sharing options...
BlackBox Posted September 20, 2011 Share Posted September 20, 2011 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)) Quote Link to comment Share on other sites More sharing options...
pBe Posted September 20, 2011 Share Posted September 20, 2011 Great stuff Renderman. Question for you. Can you use both "_X" and ":L" method of selection for ssget together in one syntax? perhaps on newer version? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted September 20, 2011 Share Posted September 20, 2011 Question for you. Can you use both "_X" and ":L" method of selection for ssget together in one syntax? perhaps on newer version? Here is what I have read lately about the same theme that you asking about pBe . Interesting thread . http://www.theswamp.org/index.php?topic=38612.msg437172#msg437172 Tharwat Quote Link to comment Share on other sites More sharing options...
pBe Posted September 20, 2011 Share Posted September 20, 2011 Here is what I have read lately about the same theme that you asking about pBe . Interesting thread . http://www.theswamp.org/index.php?topic=38612.msg437172#msg437172 Tharwat Thank you for the link Tharwat. Guess the short answer is NO. or maybe NOT YET or even NEVER. They probably have a good reason for that. I'll investigate further Quote Link to comment Share on other sites More sharing options...
Tharwat Posted September 20, 2011 Share Posted September 20, 2011 Agreed . Quote Link to comment Share on other sites More sharing options...
BlackBox Posted September 20, 2011 Share Posted September 20, 2011 Great stuff Renderman. Cheers! Question for you. Can you use both "_X" and ":L" method of selection for ssget together in one syntax? perhaps on newer version? Tharwat has already shown you another great example, courtesy of Lee. :wink: To add a bit more to the explanation, here's some additional documentation on SSGET: X Extended search (search whole database) Entire database. If you specify the X selection method and do not provide a filter-list, ssget selects all entities in the database, including entities on layers that are off, frozen, and out of the visible screen. As the "X" option searches the entire drawing database, you must utilize the filter to limit the included entity pointers in the selection set, or you must conditionally filter out what you do not want from the returned selection set... hope that makes sense. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted September 20, 2011 Share Posted September 20, 2011 You might also want to consider using SSGET's "A" mode: A All like "X" but filters frozen out Selects all objects on thawed layers. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 20, 2011 Share Posted September 20, 2011 My version: (defun c:xrlayer ( / a b c d layer ) (setq layer "G-XREF") (while (setq a (tblnext "BLOCK" (null a))) (if (= 4 (logand 4 (cdr (assoc 70 a)))) (setq b (cons "," (cons (cdr (assoc 2 a)) b))) ) ) (if (setq c (ssget "_X" (list (cons 0 "INSERT") (cons 2 (apply 'strcat (cdr b))) (cons 8 (strcat "~" layer)) ) ) ) (repeat (setq d (sslength c)) (entmod (list (cons -1 (ssname c (setq d (1- d)))) (cons 8 layer))) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
pBe Posted September 20, 2011 Share Posted September 20, 2011 Interesting approach Lee, collecting locked layer names and using that for exclusion filter Clever Quote Link to comment Share on other sites More sharing options...
pBe Posted September 20, 2011 Share Posted September 20, 2011 To add a bit more to the explanation, here's some additional documentation on SSGET: As the "X" option searches the entire drawing database, you must utilize the filter to limit the included entity pointers in the selection set, or you must conditionally filter out what you do not want from the returned selection set... hope that makes sense. Thanks for the info Renderman. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 20, 2011 Share Posted September 20, 2011 Interesting approach Lee, collecting locked layer names and using that for exclusion filter Clever Thanks pBe, I assume you are referring to my example at theSwamp Quote Link to comment Share on other sites More sharing options...
pBe Posted September 20, 2011 Share Posted September 20, 2011 Yup.. your new code here used a different approach. Block names. Nice Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.