CAD_Noob Posted March 10, 2020 Share Posted March 10, 2020 How can we determine in lisp if an xref is in model space or paper space? Anybody has a code that detaches all xref in model space but retain the xref that are in paper space? Quote Link to comment Share on other sites More sharing options...
dlanorh Posted March 10, 2020 Share Posted March 10, 2020 You could try this oldie (defun c:detachx ( / *error* c_doc c_blks b_str ss cnt obj) (defun *error* ( msg ) (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nAn Error : " msg " occurred."))) (princ) );_end_*error*_defun (setq c_doc (vla-get-activedocument (vlax-get-acad-object)) c_blks (vla-get-blocks c_doc) );end_setq (vlax-for blk c_blks (if (= :vlax-true (vlax-get-property blk 'isxref)) (setq b_str (strcat b_str "," vlax-get-property blk 'name))) );end_for (setq b_str (vl-string-trim "," b_str) ss (ssget "_X" (list '(0 . "INSERT") '(410 . "Model") (cons 2 b_str))) );end_setq (cond (ss (repeat (setq cnt (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt))))) (vla-detach obj) );end_repeat ) );end_cond (princ) );end_defun There are no checks for locked layers, so ensure all relevant layers are unlocked. I would also test it on a copy of a drawing first. 1 Quote Link to comment Share on other sites More sharing options...
ronjonp Posted March 10, 2020 Share Posted March 10, 2020 7 hours ago, CAD_Noob said: How can we determine in lisp if an xref is in model space or paper space? Anybody has a code that detaches all xref in model space but retain the xref that are in paper space? What if the same xref resides in model and paperspace? Quote Link to comment Share on other sites More sharing options...
CAD_Noob Posted March 11, 2020 Author Share Posted March 11, 2020 11 hours ago, ronjonp said: What if the same xref resides in model and paperspace? I don't have such case. Xref in Paperspace is commonly Titleblocks and legends only. Quote Link to comment Share on other sites More sharing options...
CAD_Noob Posted March 12, 2020 Author Share Posted March 12, 2020 On 3/10/2020 at 3:29 PM, dlanorh said: You could try this oldie (defun c:detachx ( / *error* c_doc c_blks b_str ss cnt obj) (defun *error* ( msg ) (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nAn Error : " msg " occurred."))) (princ) );_end_*error*_defun (setq c_doc (vla-get-activedocument (vlax-get-acad-object)) c_blks (vla-get-blocks c_doc) );end_setq (vlax-for blk c_blks (if (= :vlax-true (vlax-get-property blk 'isxref)) (setq b_str (strcat b_str "," vlax-get-property blk 'name))) );end_for (setq b_str (vl-string-trim "," b_str) ss (ssget "_X" (list '(0 . "INSERT") '(410 . "Model") (cons 2 b_str))) );end_setq (cond (ss (repeat (setq cnt (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt))))) (vla-detach obj) );end_repeat ) );end_cond (princ) );end_defun There are no checks for locked layers, so ensure all relevant layers are unlocked. I would also test it on a copy of a drawing first. i got this error : Quote Command: DETACHX An Error : bad argument type: stringp nil occurred. Command: Quote Link to comment Share on other sites More sharing options...
ronjonp Posted March 12, 2020 Share Posted March 12, 2020 b_str needs a check like so: (if (and (setq b_str (vl-string-trim "," b_str)) (setq ss (ssget "_X" (list '(0 . "INSERT") '(410 . "Model") (cons 2 b_str)))) ) ;end_setq (repeat (setq cnt (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt))))) (vla-detach obj) ) ;end_repeat ) Quote Link to comment Share on other sites More sharing options...
CAD_Noob Posted March 13, 2020 Author Share Posted March 13, 2020 8 hours ago, ronjonp said: b_str needs a check like so: (if (and (setq b_str (vl-string-trim "," b_str)) (setq ss (ssget "_X" (list '(0 . "INSERT") '(410 . "Model") (cons 2 b_str)))) ) ;end_setq (repeat (setq cnt (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt))))) (vla-detach obj) ) ;end_repeat ) (defun c:detachx ( / *error* c_doc c_blks b_str ss cnt obj) (defun *error* ( msg ) (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nAn Error : " msg " occurred."))) (princ) );_end_*error*_defun (setq c_doc (vla-get-activedocument (vlax-get-acad-object)) c_blks (vla-get-blocks c_doc) );end_setq (vlax-for blk c_blks (if (= :vlax-true (vlax-get-property blk 'isxref)) (setq b_str (strcat b_str "," vlax-get-property blk 'name))) );end_for (if (and (setq b_str (vl-string-trim "," b_str)) (setq ss (ssget "_X" (list '(0 . "INSERT") '(410 . "Model") (cons 2 b_str)))) ) ;end_setq (repeat (setq cnt (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt))))) (vla-detach obj) ) ;end_repeat ) (cond (ss (repeat (setq cnt (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt))))) (vla-detach obj) );end_repeat ) );end_cond (princ) );end_defun I incorporated this with @dlanorh lisp and i got this error : Quote Command: DETACHX An Error : bad argument type: stringp nil occurred. Command: Quote Link to comment Share on other sites More sharing options...
ronjonp Posted March 13, 2020 Share Posted March 13, 2020 (edited) This too: (vlax-for blk c_blks (if (= :vlax-true (vlax-get-property blk 'isxref)) (setq b_str (strcat (if b_str b_str "") "," vlax-get-property blk 'name)) ) ) ;end_for @dlanorh can take care of any other issues that arise Edited March 13, 2020 by ronjonp Quote Link to comment Share on other sites More sharing options...
dlanorh Posted March 13, 2020 Share Posted March 13, 2020 15 hours ago, CAD_Noob said: (defun c:detachx ( / *error* c_doc c_blks b_str ss cnt obj) (defun *error* ( msg ) (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nAn Error : " msg " occurred."))) (princ) );_end_*error*_defun (setq c_doc (vla-get-activedocument (vlax-get-acad-object)) c_blks (vla-get-blocks c_doc) );end_setq (vlax-for blk c_blks (if (= :vlax-true (vlax-get-property blk 'isxref)) (setq b_str (strcat b_str "," vlax-get-property blk 'name))) );end_for (if (and (setq b_str (vl-string-trim "," b_str)) (setq ss (ssget "_X" (list '(0 . "INSERT") '(410 . "Model") (cons 2 b_str)))) ) ;end_setq (repeat (setq cnt (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt))))) (vla-detach obj) ) ;end_repeat ) (cond (ss (repeat (setq cnt (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt))))) (vla-detach obj) );end_repeat ) );end_cond (princ) );end_defun I incorporated this with @dlanorh lisp and i got this error : Sorry, lots of problems on my work computer, my antivirus is being overenthusiastic, and intermittantly thinks the mouse driver is malware. Trying to cut and paste code is a problem right now so I've attached an updated lisp that addresses the problems. detachx.lsp Quote Link to comment Share on other sites More sharing options...
CAD_Noob Posted March 19, 2020 Author Share Posted March 19, 2020 On 3/14/2020 at 2:12 AM, dlanorh said: Sorry, lots of problems on my work computer, my antivirus is being overenthusiastic, and intermittantly thinks the mouse driver is malware. Trying to cut and paste code is a problem right now so I've attached an updated lisp that addresses the problems. detachx.lsp 1.06 kB · 1 download i still get the same error Quote Link to comment Share on other sites More sharing options...
dlanorh Posted March 19, 2020 Share Posted March 19, 2020 OK, I've altered this slightly and tested (as previously). Are you sure these are xref dwgs and not underlays of some kind? To run type detx detachx.lsp 1 Quote Link to comment Share on other sites More sharing options...
CAD_Noob Posted March 20, 2020 Author Share Posted March 20, 2020 4 hours ago, dlanorh said: OK, I've altered this slightly and tested (as previously). Are you sure these are xref dwgs and not underlays of some kind? To run type detx detachx.lsp 1.04 kB · 0 downloads It worked! Thank you so much for your time @dlanorh 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.