TYGERTY Posted March 6, 2015 Posted March 6, 2015 (edited) Hey all, I'm a new poster cause most times I can find what I need just searching the site. However, I can't find anything on Deleting a block in multiple drawings. I have 1 specific block and I want all Instances of that block deleted from like 400 drawings. Is there something out there like that? I know Lee has DeleteBlocksV1-0.lsp but I need something that will do that in a batch. and I know that it should be able be used with ObjectDBXWrapperV1-2.lsp but I don't know how to put it together. Thanks steve Edited March 6, 2015 by TYGERTY Quote
Lee Mac Posted March 6, 2015 Posted March 6, 2015 (edited) Hi Steve, and welcome to CADTutor TYGERTY said: I know Lee has DeleteBlocksV1-0.lsp but I need something that will do that in a batch. and I know that it should be able be used with ObjectDBXWrapperV1-2.lsp but I don't know how to put it together. Regarding the use of my LM:DeleteBlocks function in conjunction with my ObjectDBXWrapper function, please consider the following example: (defun c:dbtest nil (LM:odbx '(lambda ( doc ) (LM:deleteblocks doc '("Block1" "Block2" "Block3"))) nil t) (princ) ) The above code will prompt the user to select a directory of drawings to be processed, and, following a valid selection, the function will attempt to delete Block1, Block2 & Block3 (these can of course be changed to suit your requirements) from every drawing file in the selected directory. You will of course need to ensure that both my ObjectDBX Wrapper function & Delete Blocks program are loaded before running the above code. Edited February 13, 2022 by Lee Mac 1 Quote
Lee Mac Posted March 6, 2015 Posted March 6, 2015 (edited) If you need more control over which drawings are processed, you can also use my Get Files Dialog function - ensure that this program, my Delete Blocks program and my ObjectDBX Wrapper program are loaded and try the following code: (defun c:dbtest ( / lst ) (if (setq lst (LM:getfiles "Select Drawings to Process" nil "dwg;dws;dwt")) (LM:odbx '(lambda ( doc ) (LM:deleteblocks doc '("Block1" "Block2" "Block3"))) lst t) (princ "\n*Cancel*") ) (princ) ) Edited February 13, 2022 by Lee Mac Quote
vernonlee Posted July 2, 2015 Posted July 2, 2015 If you need more control over which drawings are processed, you can also use my Get Files Dialog function - ensure that this program, my Delete Blocks program and my ObjectDBX Wrapper program are loaded and try the following code: (defun c:dbtest ( / lst ) (if (setq lst (LM:getfiles "Select Drawings to Process" nil "dwg;dws;dwt")) (LM:odbx '(lambda ( doc ) (LM:deleteblocks doc '([color=red]"Block1" "Block2" "Block3"[/color]))) lst t) (princ "\n*Cancel*") ) (princ) ) Hi Lee, I tested & it worked but how would the LISP be if the BLOCKS is base on wild card? I tried *BLOCK 1* but it does not work Quote
rlx Posted July 2, 2015 Posted July 2, 2015 (edited) Lee's routine has some limmitations on what is allowed for a programm to do. You can read it all on his site http://www.lee-mac.com/odbxbase.html The supplied function should take a single argument (the VLA Document Object for each drawing processed), and follow the 'rules' of ObjectDBX, that is: No Selection Sets (use of ssget, ssname, ssdel etc) No Command calls (command "_.line" ... etc) No ent* methods (entmod, entupd etc) No access to System Variables (getvar, setvar, vla-getvariable, vla-setvariable etc You can use wildcharacters to search for multiple block's but that would invole 'ssget' and this is not allowed when you have opend a drawing with this method. In that case use easy script pro whatever or write your own script. You could place your own special block replace routine in your acad.lsp so that every time you open a drawing (with the script) all these blocks are selected and terminated... gr.R. Edited July 2, 2015 by rlx Quote
Lee Mac Posted July 2, 2015 Posted July 2, 2015 (edited) Hi Lee, I tested & it worked but how would the LISP be if the BLOCKS is base on wild card? I tried *BLOCK 1* but it does not work Try loading the following (untested) code in place of my Delete Blocks program: ;;--------------------=={ Delete Blocks }==-------------------;; ;; ;; ;; Deletes all references of a list of blocks from a drawing ;; ;; (including nested references, nested to any level). ;; ;; Proceeds to delete the associated block definitions from ;; ;; the drawing, if possible. ;; ;; ;; ;; This function is compatible with ObjectDBX. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2012 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; doc - VLA Document Object ;; ;; lst - List of blocks to be deleted (case insensitive) ;; ;;------------------------------------------------------------;; ;; Returns: List of blocks that were successfully deleted. ;; ;;------------------------------------------------------------;; (defun LM:deleteblocks ( doc lst / blc bln lck rtn ) (setq blc (vla-get-blocks doc) lst (mapcar 'strcase lst) ) (vlax-for lay (vla-get-layers doc) (if (= :vlax-true (vla-get-lock lay)) (progn (setq lck (cons lay lck)) (vla-put-lock lay :vlax-false)) ) ) (vlax-for def blc (vlax-for obj def (if (and (= "AcDbBlockReference" (vla-get-objectname obj)) (or (and (vlax-property-available-p obj 'effectivename) (setq bln (strcase (vla-get-effectivename obj))) ) (setq bln (strcase (vla-get-name obj))) ) (vl-some '(lambda ( x ) (wcmatch bln x)) lst) ) (progn (vl-catch-all-apply 'vla-delete (list obj)) (or (member bln rtn) (setq rtn (cons bln rtn))) ) ) ) ) (foreach lay lck (vla-put-lock lay :vlax-true)) (vl-remove-if '(lambda ( x ) (vl-catch-all-error-p (vl-catch-all-apply 'vla-delete (list (vla-item blc x))))) rtn) ) I will update the program on my site in due course. Edited July 3, 2015 by Lee Mac Quote
rlx Posted July 2, 2015 Posted July 2, 2015 that might just work , briljant Lee , as alwayz gr.R. Quote
vernonlee Posted July 3, 2015 Posted July 3, 2015 Try loading the following (untested) code in place of my Delete Blocks program: Hi Lee. I got an error after i loaded the LISP Command:Command: (LOAD "D:/Office/AutoCAD/lsp/DeleteBlocksMethod2.lsp") ; error: malformed list on input Quote
BIGAL Posted July 3, 2015 Posted July 3, 2015 Code is 1 bracket wrong now to find the numbers help maybe (vlax-for def blc;22 should be 1 or just missing closing for LM:deletblocks look at end of line0;;--------------------=={ Delete Blocks }==-------------------;;;00 0;; ;;;00 0;; Deletes all references of a list of blocks from a drawing ;;;00 0;; (including nested references, nested to any level). ;;;00 0;; Proceeds to delete the associated block definitions from ;;;00 0;; the drawing, if possible. ;;;00 0;; ;;;00 0;; This function is compatible with ObjectDBX. ;;;00 0;;------------------------------------------------------------;;;00 0;; Author: Lee Mac, Copyright © 2012 - www.lee-mac.com ;;;00 0;;------------------------------------------------------------;;;00 0;; Arguments: ;;;00 0;; doc - VLA Document Object ;;;00 0;; lst - List of blocks to be deleted (case insensitive) ;;;00 0;;------------------------------------------------------------;;;00 0;; Returns: List of blocks that were successfully deleted. ;;;00 0;;------------------------------------------------------------;;;00 0 ;00 1(defun LM:deleteblocks ( doc lst / blc bln lck rtn );11 2 (setq blc (vla-get-blocks doc);22 2 lst (mapcar 'strcase lst);22 1 );11 2 (vlax-for lay (vla-get-layers doc);22 3 (if (= :vlax-true (vla-get-lock lay));33 3 (progn (setq lck (cons lay lck)) (vla-put-lock lay :vlax-false));33 2 );22 1 );11 2 (vlax-for def blc;22 3 (vlax-for obj def;33 4 (if ;44 5 (and (= "AcDbBlockReference" (vla-get-objectname obj));55 6 (or ;66 7 (and (vlax-property-available-p obj 'effectivename);77 7 (setq bln (strcase (vla-get-effectivename obj)));77 6 );66 7 (setq bln (strcase (vla-get-name obj));77 6 );66 6 (vl-some '(lambda ( x ) (wcmatch bln x)) lst);66 5 );55 6 (progn;66 6 (vl-catch-all-apply 'vla-delete (list obj));66 6 (or (member bln rtn) (setq rtn (cons bln rtn)));66 5 );55 4 );44 3 );33 2 );22 2 (foreach lay lck (vla-put-lock lay :vlax-true));22 2 (vl-remove-if '(lambda ( x ) (vl-catch-all-error-p (vl-catch-all-apply 'vla-delete (list (vla-item blc x))))) rtn);22 1);11 11111; ; this should be 0 if ok Quote
Lee Mac Posted July 3, 2015 Posted July 3, 2015 Hi Lee. I got an error after i loaded the LISP Apologies - I missed a closing parenthesis - I have now updated the code in my earlier post. Quote
vernonlee Posted July 3, 2015 Posted July 3, 2015 Apologies - I missed a closing parenthesis - I have now updated the code in my earlier post. NP Lee. Will test it out when back after the weekend. Thanks man Quote
Lee Mac Posted July 3, 2015 Posted July 3, 2015 NP Lee. Will test it out when back after the weekend. Thanks man No worries - let me know how you get on Quote
vernonlee Posted July 6, 2015 Posted July 6, 2015 No worries - let me know how you get on Lee, It works SUPER WELL!! :thumbsup: Quote
Lee Mac Posted July 6, 2015 Posted July 6, 2015 Lee, It works SUPER WELL!! :thumbsup: Excellent to hear! Quote
danleebank Posted August 8, 2017 Posted August 8, 2017 Lee, I am new to this website. This is my first post, and I see this thread is rather old but maybe you can help me still. When i try to run dbtest I am able to select the directory but then nothing happens after that, the command simply ends after my selection. Its as if the deleteblocks command was never called to. The Deleteblocks, odbx, and dbtest are all loaded ahead of time as well. No errors are reported, its just that deleteblocks never "opens". I am using this code for dbtest: (defun c:dbtest nil (LM:odbx '(lambda ( doc ) (LM:deleteblocks doc '("Block1" "Block2" "Block3"))) nil t) (princ) ) The delete blocks is the new code posted by you. If you happen to see this, could you assist me? Quote
Lee Mac Posted August 8, 2017 Posted August 8, 2017 Lee, I am new to this website. This is my first post, and I see this thread is rather old but maybe you can help me still. When i try to run dbtest I am able to select the directory but then nothing happens after that, the command simply ends after my selection. Its as if the deleteblocks command was never called to. The Deleteblocks, odbx, and dbtest are all loaded ahead of time as well. No errors are reported, its just that deleteblocks never "opens". I am using this code for dbtest: (defun c:dbtest nil (LM:odbx '(lambda ( doc ) (LM:deleteblocks doc '("Block1" "Block2" "Block3"))) nil t) (princ) ) The delete blocks is the new code posted by you. If you happen to see this, could you assist me? Welcome to the forum Note that my [noparse]LM:deleteblocks & LM:odbx[/noparse] functions will not print any messages to the command-line during or after processing, therefore, after selecting the directory, the program will process all drawings silently - this is of course merely some example code, not a full-blown application for general use. I assume you have modified the block names ("Block1" "Block2" "Block3") to suit your application? PS: Please edit your post and enclose the code with code tags: [highlight][noparse] [/noparse][/highlight]Your code here[highlight][noparse] [/noparse][/highlight] Quote
danleebank Posted August 11, 2017 Posted August 11, 2017 "I assume you have modified the block names ("Block1" "Block2" "Block3") to suit your application?" Lee, this was exactly it! I dont know why but i assumed that these were variables used in the deleteblocks code and then given a value by selecting blocks in the drawing later on. However, typing in the name of the block i needed right into the code works brilliantly. Thank you very much Sir. I aspire to understand Lisp on your level some day. p.s. - I cant seem to figure out how to edit a reply that i have already made. Still quite green here. 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.