Ashishs Posted July 23, 2009 Share Posted July 23, 2009 I try it and it's work @+ Hi Patrick, Doesn't work for me. Can you check attached CAD file. Command: delblk Specify Block Name : rev Drawing Contains 36 Blocks with Name: rev Delete [A]ll or election? : 36 objects deleted.; error: Automation Error. Invalid entity name In fact, it deletes nothing. REV_54 Blocks_DELBLK.dwg Quote Link to comment Share on other sites More sharing options...
ronjonp Posted July 23, 2009 Share Posted July 23, 2009 I get the same error Patrick. 6 objects deleted.; error: Automation Error. Invalid entity name The iterative process works fine Quote Link to comment Share on other sites More sharing options...
Patrick_35 Posted July 23, 2009 Share Posted July 23, 2009 Ah yes, you're right. This is the first time that I have a problem with vla-erase. there must be something with the block Never mind, another solution Replace (vla-erase sel) by (vlax-map-collection sel 'vla-delete) @+ Quote Link to comment Share on other sites More sharing options...
Patrick_35 Posted July 23, 2009 Share Posted July 23, 2009 Ok, i understand vla-erase work fine with activespace and as you select several spaces, vla-erase bug @+ Quote Link to comment Share on other sites More sharing options...
Ashishs Posted July 25, 2009 Share Posted July 25, 2009 Vow, Finally this routine works perfectly, as required. Tnx Patrick, you rocks. & I must Admit that all of you guys here are doing a greeeeat job. Impressed a lot from day one... Cheers & keep it up. -Ashish Quote Link to comment Share on other sites More sharing options...
mkbrew Posted March 9, 2012 Share Posted March 9, 2012 I am first time poster and I know this is an old post. I apologize for necroing it, but I have been looking everywhere for a lisp that deletes a specified block, that I can use in a batch. This one is perfect, but... the problem I am having is that if the drawing does not contain the block it continues to ask for a block name and does not end the lisp and continue the batch. It grabs the next line in the batch and so on a so forth until the batch ends stuck in that one drawing. Example ** Block Not Found in Drawing ** Specify Block Name : sp20a ** Block Not Found in Drawing ** Specify Block Name : all ** Block Not Found in Drawing ** Specify Block Name : (load "dpl") ** Invalid Block Name ** Specify Block Name : dpl ** Block Not Found in Drawing ** Specify Block Name : -VIEW etc...etc... I feel kinda guilty never contributing to this forum and then asking for a favor. So I understand if Iv aggravated someone by asking for help. Anywho, best regards and thanks in advance for any help. Mary K Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 9, 2012 Share Posted March 9, 2012 Hi Mary, The following is quickly written, but should be suitable for use in a Script: [color=green];; Delete Block - Lee Mac ;; Deletes all references of a block from a drawing, including nested references (nested to any level). ;; Proceeds to delete the block definition from the drawing, if possible. ;; Arguments: ;; block - block to be deleted (not case-sensitive)[/color] ([color=BLUE]defun[/color] DeleteBlock ( block [color=BLUE]/[/color] doc lst ) ([color=BLUE]setq[/color] block ([color=BLUE]strcase[/color] block)) ([color=BLUE]if[/color] ([color=BLUE]tblsearch[/color] [color=MAROON]"BLOCK"[/color] block) ([color=BLUE]progn[/color] ([color=BLUE]setq[/color] doc ([color=BLUE]vla-get-activedocument[/color] ([color=BLUE]vlax-get-acad-object[/color]))) ([color=BLUE]vlax-for[/color] lay ([color=BLUE]vla-get-layers[/color] doc) ([color=BLUE]if[/color] ([color=BLUE]eq[/color] [color=BLUE]:vlax-true[/color] ([color=BLUE]vla-get-lock[/color] lay)) ([color=BLUE]progn[/color] ([color=BLUE]setq[/color] lst ([color=BLUE]cons[/color] lay lst)) ([color=BLUE]vla-put-lock[/color] lay [color=BLUE]:vlax-false[/color]) ) ) ) ([color=BLUE]vlax-for[/color] def ([color=BLUE]vla-get-blocks[/color] doc) ([color=BLUE]vlax-for[/color] obj def ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]eq[/color] [color=MAROON]"AcDbBlockReference"[/color] ([color=BLUE]vla-get-objectname[/color] obj)) ([color=BLUE]or[/color] ([color=BLUE]and[/color] ([color=BLUE]vlax-property-available-p[/color] obj 'effectivename) ([color=BLUE]eq[/color] block ([color=BLUE]strcase[/color] ([color=BLUE]vla-get-effectivename[/color] obj))) ) ([color=BLUE]eq[/color] block ([color=BLUE]strcase[/color] ([color=BLUE]vla-get-name[/color] obj))) ) ) ([color=BLUE]vl-catch-all-apply[/color] '[color=BLUE]vla-delete[/color] ([color=BLUE]list[/color] obj)) ) ) ) ([color=BLUE]vl-catch-all-apply[/color] '[color=BLUE]vla-delete[/color] ([color=BLUE]list[/color] ([color=BLUE]vla-item[/color] ([color=BLUE]vla-get-blocks[/color] doc) block))) ([color=BLUE]foreach[/color] lay lst ([color=BLUE]vla-put-lock[/color] lay [color=BLUE]:vlax-true[/color]) ) ) ) ([color=BLUE]princ[/color]) ) ([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color]) Call it like this: (DeleteBlock [color=darkred]"Your Block"[/color]) Where "Your Block" is the name of the block to be deleted (not case-sensitive). It will delete all references of the block in all layouts of the drawing, including references on locked layers, and also including all nested references, nested to any level. Finally it will delete the block definition from the drawing. If you need help using it, just ask. Lee Quote Link to comment Share on other sites More sharing options...
mkbrew Posted March 9, 2012 Share Posted March 9, 2012 Lee, You Rock! Thank you so much! It works like a charm! Running in the backgound as I type!! WOOT! Mary K Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 9, 2012 Share Posted March 9, 2012 Excellent to hear Mary, you're very welcome! Quote Link to comment Share on other sites More sharing options...
Bobzy20 Posted December 3, 2013 Share Posted December 3, 2013 (edited) Is there any way to modify the code so it will search for all block names without an exact match, for example. Block Names: G_Walls_Board$0 G_Walls_Board$1 G_Walls_Board$2 G_Walls_Board$3 G_Walls_Board$4 So it would find all 5 blocks above containing the word: G_Walls_Board Edited December 4, 2013 by Bobzy20 Quote Link to comment Share on other sites More sharing options...
Bobzy20 Posted December 3, 2013 Share Posted December 3, 2013 Anybody? Really need this for work tomorrow. Lee Daddy Mac? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 4, 2013 Share Posted December 4, 2013 Is there any way to modify the code so it will search for all block names without an exact match, for example. Block Names: G_Walls_Board$0 G_Walls_Board$1 G_Walls_Board$2 G_Walls_Board$3 G_Walls_Board$4 So it would find all 5 blocks above containing the word: G_Walls_Board Try the following: [color=GREEN];; Delete Block - Lee Mac[/color] [color=GREEN];; Deletes all references of a block from a drawing, including nested references (nested to any level).[/color] [color=GREEN];; Proceeds to delete the block definition from the drawing, if possible.[/color] [color=GREEN];; Arguments:[/color] [color=GREEN];; block - block to be deleted (not case-sensitive)[/color] ([color=BLUE]defun[/color] deleteblock ( blk [color=BLUE]/[/color] doc lst ) ([color=BLUE]setq[/color] blk ([color=BLUE]strcase[/color] blk)) ([color=BLUE]vlax-for[/color] lay ([color=BLUE]vla-get-layers[/color] ([color=BLUE]setq[/color] doc ([color=BLUE]vla-get-activedocument[/color] ([color=BLUE]vlax-get-acad-object[/color])))) ([color=BLUE]if[/color] ([color=BLUE]eq[/color] [color=BLUE]:vlax-true[/color] ([color=BLUE]vla-get-lock[/color] lay)) ([color=BLUE]progn[/color] ([color=BLUE]setq[/color] lst ([color=BLUE]cons[/color] lay lst)) ([color=BLUE]vla-put-lock[/color] lay [color=BLUE]:vlax-false[/color]) ) ) ) ([color=BLUE]vlax-for[/color] def ([color=BLUE]vla-get-blocks[/color] doc) ([color=BLUE]vlax-for[/color] obj def ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]=[/color] [color=MAROON]"AcDbBlockReference"[/color] ([color=BLUE]vla-get-objectname[/color] obj)) ([color=BLUE]or[/color] ([color=BLUE]and[/color] ([color=BLUE]vlax-property-available-p[/color] obj 'effectivename) ([color=BLUE]wcmatch[/color] ([color=BLUE]strcase[/color] ([color=BLUE]vla-get-effectivename[/color] obj)) blk) ) ([color=BLUE]wcmatch[/color] ([color=BLUE]strcase[/color] ([color=BLUE]vla-get-name[/color] obj)) blk) ) ) ([color=BLUE]vl-catch-all-apply[/color] '[color=BLUE]vla-delete[/color] ([color=BLUE]list[/color] obj)) ) ) ) ([color=BLUE]vlax-for[/color] def ([color=BLUE]vla-get-blocks[/color] doc) ([color=BLUE]if[/color] ([color=BLUE]wcmatch[/color] ([color=BLUE]vla-get-name[/color] def) blk) ([color=BLUE]vl-catch-all-apply[/color] '[color=BLUE]vla-delete[/color] ([color=BLUE]list[/color] def)) ) ) ([color=BLUE]foreach[/color] lay lst ([color=BLUE]vla-put-lock[/color] lay [color=BLUE]:vlax-true[/color])) ([color=BLUE]princ[/color]) ) ([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color]) Call with: (deleteblock "G_Walls_Board$#") Anybody? Really need this for work tomorrow. Lee Daddy Mac? Please understand that repeatedly pestering us on the forum and via direct emails will not get your question answered any sooner, but will usually have the opposite effect. Remember that our time contributing here is voluntary, we receive no remuneration for the time and effort that we donate. Quote Link to comment Share on other sites More sharing options...
Bobzy20 Posted December 4, 2013 Share Posted December 4, 2013 Thanks Lee for your help. Sorry for the pestering via my 1 additional post and 1 direct email. I won't be doing that again. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 4, 2013 Share Posted December 4, 2013 Patience is a virtue Bob Quote Link to comment Share on other sites More sharing options...
Bobzy20 Posted December 4, 2013 Share Posted December 4, 2013 The LISP is loaded but I’m not sure how to make it run, what do I type in? I thought it would be: deleteblock Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 4, 2013 Share Posted December 4, 2013 (deleteblock "G_Walls_Board$#") Quote Link to comment Share on other sites More sharing options...
Bobzy20 Posted December 4, 2013 Share Posted December 4, 2013 Thanks, i'll check it out tomorrow and let you know. Quote Link to comment Share on other sites More sharing options...
Bobzy20 Posted December 4, 2013 Share Posted December 4, 2013 (edited) Strange, it works fine on a test drawing I created to run the test but not on the one I wanted it for! Still the drawing I wanted to use it on was drawn in microGDS and exported as a DWG, this is why all the blocks are numbered $1, $2, $3 and so on. They are the same block used multiple times but when you export it for some reason it numbers them individually. Anyway thanks for your help Lee. Edited December 5, 2013 by Bobzy20 Quote Link to comment Share on other sites More sharing options...
Bobzy20 Posted December 5, 2013 Share Posted December 5, 2013 Lee I’m currently using your DeleteBlocksV1-0.lsp - Amazing little tool. http://www.lee-mac.com/deleteblocks.html Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 5, 2013 Share Posted December 5, 2013 Thank you Bob - I'm glad you find it useful 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.