alanjt Posted February 17, 2011 Posted February 17, 2011 My contribution (will also deal with locked layers). (defun c:DBD (/ *error* _name obj name def ss locklist blocks) ;; Delete all instances of selected block (nested blocks and definition also removed) ;; Alan J. Thompson, 02.17.11 (vl-load-com) (defun *error* (msg) (foreach x locklist (vla-put-lock x :vlax-true)) (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,"))) (princ (strcat "\nError: " msg)) ) ) (defun _name (obj) (vlax-get-property obj (if (vlax-property-available-p obj 'EffectiveName) 'EffectiveName 'Name ) ) ) (if (setq obj (car (entsel "\nSelect block definition to remove: "))) (cond ((not (eq "AcDbBlockReference" (vla-get-objectname (setq obj (vlax-ename->vla-object obj))))) (princ "\nInvalid object!") ) ((eq 1 (vlax-get (setq def (vla-item (setq blocks (vla-get-blocks (cond (*AcadDoc*) ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object) ) ) ) ) ) ) (setq name (_name obj)) ) ) 'isXRef ) ) (princ "\nBlock definition must not be an XRef!") ) ((progn (initget 0 "Yes No") (vl-position (getkword (strcat "\nDelete all instance of \"" name "\" block? [Yes/No] <Yes>: ")) '("Yes" nil) ) ) (if (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`*U*," name))))) (progn (vlax-for x (vla-get-layers *AcadDoc*) (if (eq (vla-get-lock x) :vlax-true) (progn (setq locklist (cons x locklist)) (vla-put-lock x :vlax-false) ) ) ) (vlax-for x (setq ss (vla-get-activeselectionset *AcadDoc*)) (if (eq (_name x) name) (vla-delete x) ) ) (vla-delete ss) (vlax-for block blocks (vlax-for x block (if (and (eq (vla-get-objectname x) "AcDbBlockReference") (eq (vla-get-name x) name)) (vla-delete x) ) ) ) (vla-delete def) (vla-regen *AcadDoc* acAllViewports) (alert (strcat "Block \"" name "\" has been removed.")) ) ) ) ) ) (*error* nil) (princ) ) Quote
BlackBox Posted February 17, 2011 Posted February 17, 2011 My contribution ... Contribution... you saved the OP's world, Superhero. There's a lot to digest in there, too. Cheers, bud! Quote
alanjt Posted February 17, 2011 Posted February 17, 2011 Oh yeah, I forgot to mention, it will also ignore selected XRefs. Quote
BlackBox Posted February 17, 2011 Posted February 17, 2011 Oh yeah, I forgot to mention, it will also ignore selected XRefs. I was going to ask about that... if XRef is selected, why not vla-detach? Quote
alanjt Posted February 17, 2011 Posted February 17, 2011 I was going to ask about that... if XRef is selected, why not vla-detach? One could if that was necessary. Seemed to me that I wouldn't want to be touching XRefs at all - why I added the check. Am I wrong in this assumption? I've only use XRefs for bringing in entire plans. Quote
BlackBox Posted February 17, 2011 Posted February 17, 2011 One could if that was necessary. Seemed to me that I wouldn't want to be touching XRefs at all - why I added the check. Am I wrong in this assumption? I've only use XRefs for bringing in entire plans. I am not suggesting that your offering is wrong at all - perhaps it's the way I work. As a result of lock and fade, it is very easy to identify XRefs in my drawings; my thinking assumed that the user intentionally selected an XRef. *IF* vla-detach were implemented, and an accidental selection occurred, that would pose an issue to the user. Quote
alanjt Posted February 17, 2011 Posted February 17, 2011 I am not suggesting that your offering is wrong at all - perhaps it's the way I work. As a result of lock and fade, it is very easy to identify XRefs in my drawings; my thinking assumed that the user intentionally selected an XRef. *IF* vla-detach were implemented, and an accidental selection occurred, that would pose an issue to the user. I know.If it were an XRef, I would definitely prompt user before actually detaching. Quote
alanjt Posted February 17, 2011 Posted February 17, 2011 *IF* vla-detach were implemented, and an accidental selection occurred, that would pose an issue to the user. Another reason why I prompt the use to verify that the selected block *name* is the one they want removed. Quote
BlackBox Posted February 17, 2011 Posted February 17, 2011 I know.If it were an XRef, I would definitely prompt user before actually detaching. Another reason why I prompt the use to verify that the selected block *name* is the one they want removed. Like I said, there's a lot to digest in there. Thanks for entertaining my question(s). Quote
alanjt Posted February 17, 2011 Posted February 17, 2011 Like I said, there's a lot to digest in there. Thanks for entertaining my question(s). Anytime. I'm always happy to answer - when I can. Quote
alanjt Posted February 17, 2011 Posted February 17, 2011 Like I said, there's a lot to digest in there. I should have denoted my work, but I wrote it real quick. Quote
Jaap Marchal Posted February 17, 2011 Author Posted February 17, 2011 Wel wel wel, keeps you folks from the street. But it isnt wat i ment. Iàm looking for a lisp that askes for a blockname (embedded) and delete it from the drawing. The embedded block is not always visable (visability -dynamic block). The name from the embedded block is BIS. The couse of using caps in previous threats is, i did this from work en i always uses caps in drawings..........sorry Jaap Quote
Tharwat Posted February 17, 2011 Posted February 17, 2011 Wel wel wel, keeps you folks from the street. What do you mean by that ? Quote
Jaap Marchal Posted February 17, 2011 Author Posted February 17, 2011 That you are so busy with this threat............meaning nothing special with this (Wel wel wel, keeps you folks from the street) . I like to see this, from people who are so into lisp and iàm not. Not smart enough i guess Jaap Quote
alanjt Posted February 17, 2011 Posted February 17, 2011 Well, good thing I was writing it more for RenderMan and Tharwat. I'm done. Quote
Tharwat Posted February 17, 2011 Posted February 17, 2011 Well, good thing I was writing it more for RenderMan and Tharwat. I'm done. Highly appreciated Alanjt. And their way of replies from the first time kept me out of writing or extending my codes to include the nested blocks in blocks definitions . Best regards. Tharwat Quote
Lee Mac Posted February 18, 2011 Posted February 18, 2011 Well, good thing I was writing it more for RenderMan and Tharwat. I'm done. Know how you feel mate - it was poor wording using 'embedded' as opposed to 'nested'. For completeness: (defun c:DeleteNestedBlocks nil (vl-load-com) (vlax-for block (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)) ) (if (and (eq :vlax-false (vla-get-isXref block)) (eq :vlax-false (vla-get-isLayout block)) ) (vlax-for obj block (if (and (eq "AcDbBlockReference" (vla-get-Objectname obj)) (eq "BIS" (vla-get-name obj)) ) (vl-catch-all-apply 'vla-delete (list obj)) ) ) ) ) (princ) ) You will need to Regen the Inserts to see the results, and also Purge the excess nested blocks from the block table. Quote
Lee Mac Posted February 18, 2011 Posted February 18, 2011 I like to see this, from people who are so into lisp and iàm not. Perhaps you should be - you have enough need for it. Quote
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.