Jaap Marchal Posted February 17, 2011 Posted February 17, 2011 HELLO, i`AM LOOKING FOR A LISP TO FORCE DELETE A (EMBEDDED)BLOCK FROM A DRAWING. SOMETHING LIKE LAYER DELETE. THANKS JAAP Quote
ReMark Posted February 17, 2011 Posted February 17, 2011 Purge command with Block option? Are the blocks named or anonymous? Quote
Tharwat Posted February 17, 2011 Posted February 17, 2011 Check this out ..... (defun c:test (/ ss ss1 e Blks) ; Tharwat 17. 02. 2011 (if (and (setq ss (ssget "_+.:S" '((0 . "INSERT")))) (setq ss1 (ssname ss 0)) (setq e (entget ss1)) ) (progn (setq Blks (ssget "_x" (list '(0 . "INSERT") (cons 2 (cdr (assoc 2 e)))))) (command "_.Erase" Blks "") ) (princ) ) (princ) ) Tharwat Quote
Jaap Marchal Posted February 17, 2011 Author Posted February 17, 2011 NO, IS NOT WORKING. WHEN I GIVE THE COMMAND "TEST". IT ASKS TO SELECT.--> NOTHING IS DONE. AUTOCAD COMES BACK WITH: Command: TEST Unknown command "TEST". Press F1 for help. WORKING WITH AUTOCAD ELECTRICAL 2010 JAAP Quote
Tharwat Posted February 17, 2011 Posted February 17, 2011 On the contrary , It does the job quickly . But with your Electrical version of Cad which is I have no idea if would except Lisp or not though . Quote
Tiger Posted February 17, 2011 Posted February 17, 2011 (edited) NO, IS NOT WORKING. WHEN I GIVE THE COMMAND "TEST". IT ASKS TO SELECT.-->NOTHING IS DONE. AUTOCAD COMES BACK WITH: Command: TEST Unknown command "TEST". Press F1 for help. WORKING WITH AUTOCAD ELECTRICAL 2010 JAAP Sounds like you haven't loaded the lisp correctly, see these instructions. Also, please stop with the caps, being shout at is not fun. Edited February 17, 2011 by Tiger added link Quote
BlackBox Posted February 17, 2011 Posted February 17, 2011 You may want to reconsider this line: (defun c:test (/ ss ss1 e Blks) ; Tharwat 17. 02. 2011 (if (and (setq ss (ssget "_+.:S" '((0 . "INSERT")))) (setq ss1 (ssname ss 0)) (setq e (entget ss1)) ) (progn (setq Blks (ssget "_x" (list '(0 . "INSERT") [color=red][b]([/b][/color][color=red]cons 2 (cdr[/color] [color=blue][b]([/b]assoc 2 e[b])[/b][/color][color=red])[b])[/b][/color]))) (command "_.Erase" Blks "") ) (princ) ) (princ) ) For fun, here's another option: (defun c:FOO (/ *acadDoc* eName ss blockItem) (vl-load-com) (vla-startundomark (setq *acadDoc* (vla-get-activedocument (vlax-get-acad-object)))) (if (and (setq eName (car (entsel "\nSelect the Block You Wish to Delete: "))) (setq ss (ssget "_x" (list '(0 . "INSERT") (assoc 2 (entget eName)))))) (progn (vlax-for x (setq ss (vla-get-activeselectionset *acadDoc*)) (cond (blockItem) ((setq blockItem (vla-item (vla-get-blocks *acadDoc*) (vla-get-effectivename x))))) (vla-delete x)) (vla-delete blockItem) (vla-delete ss))) (vla-endundomark *acadDoc*) (princ)) Option #2 will also remove the block reference from the blocks collection. Quote
alanjt Posted February 17, 2011 Posted February 17, 2011 You may want to reconsider this line: Always cracks me up when I see that. Quote
Tharwat Posted February 17, 2011 Posted February 17, 2011 Hello Renderman . I guess that the following two lines are the same according to the use of them . (cons 2 (cdr (assoc 2 e))) (assoc 2 e) But for the situation of building the search filtering list , the cons might be better than (assoc 2 e) What you think ? Quote
BlackBox Posted February 17, 2011 Posted February 17, 2011 Always cracks me up when I see that. You'll laugh, I always try to say it nicely... because I know there's one coming around the corner, pointed at me. Quote
BlackBox Posted February 17, 2011 Posted February 17, 2011 I guess that the following two lines are the same according to the use of them . (cons 2 (cdr (assoc 2 e))) (assoc 2 e) More specifically, they yield the same result... that is what's important. But for the situation of building the search filtering list , the cons might be better than (assoc 2 e) What you think ? I think not... I'm not a fan of doing extra work for the same result. Edit: How's the old saying go... "Brevity is the Soul of Wit" Quote
Tharwat Posted February 17, 2011 Posted February 17, 2011 I think not... I'm not a fan of doing extra work for the same result. Edit: How's the old saying go... "Brevity is the Soul of Wit" But I am a fan of learning a lot, and by time knowledge would become easily obtained and given at the right situation. And would become more genius than Genious :wink: Regards Quote
alanjt Posted February 17, 2011 Posted February 17, 2011 Hello Renderman . I guess that the following two lines are the same according to the use of them . (cons 2 (cdr (assoc 2 e))) (assoc 2 e) But for the situation of building the search filtering list , the cons might be better than (assoc 2 e) What you think ? All cons is going is recreating a dotted pair list. Why create extra work for yourself? Quote
BlackBox Posted February 17, 2011 Posted February 17, 2011 But I am a fan of learning a lot, and by time knowledge would become easily obtained and given at the right situation.And would become more genius than Genious :wink: Regards That's great, Tharwat... but did you understand the point being made? I think that when you (genuinely) compare the amount of code/work in yours: ... (if (and (setq ss (ssget "_+.:S" '((0 . "INSERT")))) (setq ss1 (ssname ss 0)) (setq e (entget ss1))) (progn ([color=black]setq Blks (ssget "_x" (list '(0 . "INSERT") (cons 2 (cdr (assoc 2 e))))))[/color][color=black]...[/color] ... To that of mine: [color=black]...[/color] [color=black](if (and [/color][color=black](setq eName (car (entsel "\nSelect the Block You Wish to Delete: ")))[/color] [color=black] (setq ss (ssget "_x" (list '(0 . "INSERT") (assoc 2 (entget eName))))))[/color] ... ... You will see (appreciate?) the inherent advantage to the latter. Cheers! Quote
Tharwat Posted February 17, 2011 Posted February 17, 2011 I think that when you (genuinely) compare the amount of code/work in yours: Cheers! Yes Renderman . That's what I intended to code at the beginning of the first post and I do not know why I changed my mind with it to ssget . ... You will see (appreciate?) the inherent advantage to the latter. Here is the message that I have received while invoking your codes , I do not why . Command: foo Select the Block You Wish to Delete: ; error: Automation Error. Object is referenced Many thanks Quote
Tharwat Posted February 17, 2011 Posted February 17, 2011 All cons is going is recreating a dotted pair list. Why create extra work for yourself? Yeah.... I should have used it with assoc only without the cons function . Appreciated Quote
BlackBox Posted February 17, 2011 Posted February 17, 2011 Here is the message that I have received while invoking your codes , I do not why . Command: foo Select the Block You Wish to Delete: ; error: Automation Error. Object is referenced Interesting... which line breaks in VLIDE? First guess would be the line that deletes the block reference... the error suggests that the block exists elsewhere, perhaps nested inside of another block? Admittedly, my code does not handle nested blocks, only primary. Quote
Tharwat Posted February 17, 2011 Posted February 17, 2011 First guess would be the line that deletes the block reference... the error suggests that the block exists elsewhere, perhaps nested inside of another block? Admittedly, my code does not handle nested blocks, only primary. Great guess . The selected Block was nested to another which caused that message to appear . Appreciated. Tharwat Quote
BlackBox Posted February 17, 2011 Posted February 17, 2011 Great guess . The selected Block was nested to another which caused that message to appear . Ohhhh! That's what the OP meant by '(embedded)'. I'm busy at the moment, but will try to revist the original request, given this late revelation.... Quote
Tharwat Posted February 17, 2011 Posted February 17, 2011 Ohhhh! That's what the OP meant by '(embedded)'. I'm busy at the moment, but will try to revist the original request, given this late revelation.... We have been dancing out of the ring since the first post . Although my codes would escape slowly. Thanks 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.