vernonlee Posted March 13, 2015 Share Posted March 13, 2015 How does this LISP work? I key in the following but do not work DELETEBLOCK LIFT$0$A$C5AD1096B (DeleteBlock "LIFT$0$A$C5AD1096B") This is the LISP i am using from LEE ;; 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) (defun DeleteBlock ( block / doc lst ) (setq block (strcase block)) (if (tblsearch "[b][color=darkred]LIFT$0$A$C5AD1096B[/color][/b]" block) (progn (setq doc (vla-get-activedocument (vlax-get-acad-object))) (vlax-for lay (vla-get-layers doc) (if (eq :vlax-true (vla-get-lock lay)) (progn (setq lst (cons lay lst)) (vla-put-lock lay :vlax-false) ) ) ) (vlax-for def (vla-get-blocks doc) (vlax-for obj def (if (and (eq "AcDbBlockReference" (vla-get-objectname obj)) (or (and (vlax-property-available-p obj 'effectivename) (eq block (strcase (vla-get-effectivename obj))) ) (eq block (strcase (vla-get-name obj))) ) ) (vl-catch-all-apply 'vla-delete (list obj)) ) ) ) (vl-catch-all-apply 'vla-delete (list (vla-item (vla-get-blocks doc) block))) (foreach lay lst (vla-put-lock lay :vlax-true) ) ) ) (princ) ) (vl-load-com) (princ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 13, 2015 Share Posted March 13, 2015 You should not modify the code in any way, but instead call the function with the name of the block to be deleted, i.e.: (DeleteBlock "LIFT$0$A$C5AD1096B") I would also recommmend that you refer to my Delete Blocks program here; upon loading the program you can either use the delblocks command and select the blocks from the dialog, or call the LM:deleteblocks function with a list of block names, e.g.: (LM:deleteblocks '("LIFT$0$A$C5AD1096B")) Quote Link to comment Share on other sites More sharing options...
vernonlee Posted March 13, 2015 Share Posted March 13, 2015 Oh I see. WIll try it next week. Btw, i also tried your delete block program but the width of the dialog box can't seen to be adjusted thus i cannot see the full name of the block. Incidenly i did email you this query through your website. Perhaps you can advise me here? Thanks Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 13, 2015 Share Posted March 13, 2015 Btw, i also tried your delete block program but the width of the dialog box can't seen to be adjusted thus i cannot see the full name of the block. Incidenly i did email you this query through your website. Perhaps you can advise me here? I responded to your email some time ago. Quote Link to comment Share on other sites More sharing options...
vernonlee Posted March 14, 2015 Share Posted March 14, 2015 Thanks Lee. Just saw it. Quote Link to comment Share on other sites More sharing options...
vernonlee Posted March 16, 2015 Share Posted March 16, 2015 Hi Lee. Retested the previous LISP I was clarify about & it works now. I intend to run it through a script to remove multiple blocks at once. eg. door block, window block, grid block, text block How to run without multiple scripts? Something like this? ^C^C(deleteblock "door block, window block, grid block, text block"); Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 16, 2015 Share Posted March 16, 2015 (edited) For multiple blocks, you should use my [noparse]LM:DeleteBlocks[/noparse] function which may be called with the ActiveX Document object and a list of block names defined in the Blocks Collection for the supplied Document, e.g. for blocks defined in the active drawing, you would use: (LM:deleteblocks (vla-get-activedocument (vlax-get-acad-object)) '("door block" "window block" "grid block") ) You may find this thread of interest. Edited March 18, 2015 by Lee Mac Quote Link to comment Share on other sites More sharing options...
vernonlee Posted March 16, 2015 Share Posted March 16, 2015 Wow. Thanks Lee for the link of the other thread. Will be useful. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 16, 2015 Share Posted March 16, 2015 You're welcome - just be aware that the use of ObjectDBX will cause all drawings to be saved to the native version (i.e. the highest available version in the host software), and drawing thumbnails will be lost until the next 'manual' save. Lee Quote Link to comment Share on other sites More sharing options...
vernonlee Posted March 18, 2015 Share Posted March 18, 2015 Hi Lee, Not sure what i am doing wrong but i have the following error when i enter this command Command: (LM:deleteblocks '("X-COMMGRID-1" "X-COMMGRID (office)" "X-SECLINE" "X-OFF-ELEVLINE" "X-OFF-ELEVLINE" "xBNRY")) [color=red][b]; error: too few arguments[/b][/color] Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 18, 2015 Share Posted March 18, 2015 Hi Lee, Not sure what i am doing wrong but i have the following error when i enter this command Command: (LM:deleteblocks '("X-COMMGRID-1" "X-COMMGRID (office)" "X-SECLINE" "X-OFF-ELEVLINE" "X-OFF-ELEVLINE" "xBNRY")) [color=red][b]; error: too few arguments[/b][/color] My apologies - you will also need to supply the Document object containing the Blocks Collection in which the blocks are defined, for example, for the active drawing you would use: (LM:deleteblocks (vla-get-activedocument (vlax-get-acad-object)) '("X-COMMGRID-1" "X-COMMGRID (office)" "X-SECLINE" "X-OFF-ELEVLINE" "X-OFF-ELEVLINE" "xBNRY") ) I will update my earlier post for the benefit of others who may read this thread. Quote Link to comment Share on other sites More sharing options...
vernonlee Posted March 18, 2015 Share Posted March 18, 2015 Hi Lee, How do i incorporate it into a LISP form for multiple blocks? I copied the LISP from your linked thread & replace with your new command but got an error instead:- (defun c:test ( / lst ) (if (setq lst (LM:getfiles "Select Drawings to Process" nil "dwg;dws;dwt")) (LM:odbx '(lambda ( doc ) (LM:deleteblocks (vla-get-activedocument (vlax-get-acad-object)) '("X-COMMGRID-1" "X-COMMGRID (office)" "X-SECLINE" "X-OFF-ELEVLINE" "X-OFF-ELEVLINE" "xBNRY") )) lst t) (princ "\n*Cancel*") ) (princ) ) [color=red][b]Command: TEST ; error: no function definition: LM:GETFILES[/b][/color] Also when i just paste the command directly, the blocks indicated got deleted but at the end there is an error. Should i be concern? Command: (LM:deleteblocks(_> (vla-get-activedocument (vlax-get-acad-object)) (_> '("X-COMMGRID-1" "X-COMMGRID (office)" "X-SECLINE" "X-OFF-ELEVLINE" "X-OFF-ELEVLINE" "xBNRY") (_> ) ; error: Automation Error. Key not found Thanks Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 18, 2015 Share Posted March 18, 2015 How do i incorporate it into a LISP form for multiple blocks? I copied the LISP from your linked thread & replace with your new command but got an error instead:- (defun c:test ( / lst ) (if (setq lst (LM:getfiles "Select Drawings to Process" nil "dwg;dws;dwt")) (LM:odbx '(lambda ( doc ) (LM:deleteblocks (vla-get-activedocument (vlax-get-acad-object)) '("X-COMMGRID-1" "X-COMMGRID (office)" "X-SECLINE" "X-OFF-ELEVLINE" "X-OFF-ELEVLINE" "xBNRY") )) lst t) (princ "\n*Cancel*") ) (princ) ) [color=red][b]Command: TEST ; error: no function definition: LM:GETFILES[/b][/color] You cannot simply copy the expression I posted earlier into the other program, as the program from the linked thread is referencing the ObjectDBX Document as opposed to the Active Document. Where the code in the linked thread is concerned, you should only change the block names highlighted in red; the document object should remain as 'doc' (this symbol is assigned the ObjectDBX Document object for every drawing processed). You are receiving the error 'no function definition: LM:GETFILES' because you haven't loaded my LM:getfiles function. As noted in the linked thread: 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... Also when i just paste the command directly, the blocks indicated got deleted but at the end there is an error. Should i be concern? I'm not entirely sure why you are receiving this error (the error indicates that an item is not present in a VL Collection), as my Delete Blocks function will remove any blocks which are not defined in the Blocks Collection of the supplied Document object from the supplied list of block names before processing the blocks. Do you receive this error consistently for every use of the function? 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.