john_waggs Posted February 14, 2013 Posted February 14, 2013 I am hoping there's a routine out there already that would do the following, although I could not find one on the site. I am reaching out to you experienced programmers out there. I need a lisp routine that would search the drawing database for the 3 following blocks: gennotes, gennotes-R3-flood, gennotes-R3-flood. IF found, the insert command would then insert= to redefine the block, cancel the command (since the block is redefined it doesn't have to be inserted again), save the drawing (overwriting the existing without prompting), then exit autocad. The drawing will only have 1 of these blocks and not all of them. If the routine searched the drawing and did not find one of these blocks, the routine would just quit out of the drawing. Any help would be great! Thanks in advance, John Quote
BIGAL Posted February 14, 2013 Posted February 14, 2013 Maybe something like this ps not tested. You may need to modify the insert line do a manual insert write down steps script open dwg1 (load "blkupdate") close y open dwg2 (load "blkupdate") close y open dwg2 (load "blkupdate") close y (setq ss1 (ssget "X" '((0 . "INSERT")))) (setq n (sslength ss1)) (setq index 0) (repeat n (setq en (ssname ss1 index)) (setq index (+ index 1)) (setq el (entget en)) (setq blkname (assoc 2 el)) (if (= blkname "gennotes") (command "_insert" "[url="file://\\myblocks\\gennotes"]C:\\myblocks\\gennotes[/url].dwg" "y" 0,0 1 1 0) ; check this line ) (if (= blkname "gennotes-R3-flood") (command "_insert" "[url="file://\\myblocks\\gennotes-R3-flood"]\\myblocks\\gennotes-R3-flood[/url]" "y" 0,0 1 1 0) ) (if (= blkname "gennotes-R2-flood") (command "_insert" "[url="file://\\myblocks\\gennotes-R2-flood"]\\myblocks\\gennotes-R2-flood[/url]" "y" 0,0 1 1 0) ) ) ; repeat (setq ss1 nil n nil blkname nil) (princ) Quote
Lee Mac Posted February 15, 2013 Posted February 15, 2013 Try this: [ Note: two of your block names were identical, I assume you meant 'R2' for the second block ] (defun c:redef ( / file ) (foreach block '("gennotes" "gennotes-R2-flood" "gennotes-R3-flood") (if (and (tblsearch "BLOCK" block) (setq file (findfile (strcat block ".dwg")))) (command "_.-insert" (strcat block "=" file) nil) ) ) (princ) ) You can run the above program through a Script to operate on multiple drawings. To construct & run the necessary Script file, you could even use my old Script Writer program. If you wish to use this program, perform the following steps: Save the above c:redef program as redef.lsp in your AutoCAD Support Path. Download & load my Script Writer AutoLISP program in a new blank drawing. Run the program by typing wscript at the command-line. In the 'Script Line' edit box, type/copy the following (including all spaces!): _.open *file* (if (load "redef.lsp" nil) (c:redef)) _.qsave _.close Select the directory of drawings to be processed and whether to process all subdirectories of the selected directory. Click 'Run Script!' to run the script. Whenever performing automated operations on a set of several drawing, I would always suggest working with copies of drawings, just in case. I hope this helps! Lee Quote
dbroada Posted February 15, 2013 Posted February 15, 2013 I have no doubt that Lee's solution was perfect but it could also have been done with a script (for LT users) by INSERTing each block in turn followed by an ERASE L(ast) and when finished PURGE the drawing. Quote
john_waggs Posted February 20, 2013 Author Posted February 20, 2013 Thanks BigAl and Lee Mac! You guys are awesome! Sorry it took so long to reply. The link that was sent to me in my email didn't work a few times I tried it. I also didn't get the auto-email from Lee Mac's reply. But I'm happy I was able to get back here and check. I will try these out when I come back to town week after next and let you know how they worked out! Thanks again. John Quote
Janouren Posted May 17 Posted May 17 (edited) On 15/02/2013 at 01:21, Lee Mac said: Try this: [ Note: two of your block names were identical, I assume you meant 'R2' for the second block ] (defun c:redef ( / file ) (foreach block '("gennotes" "gennotes-R2-flood" "gennotes-R3-flood") (if (and (tblsearch "BLOCK" block) (setq file (findfile (strcat block ".dwg")))) (command "_.-insert" (strcat block "=" file) nil) ) ) (princ) ) I had similiar request as OP and I confirm that this solution by Lee Mac works great in 2024. Edited May 17 by Janouren 1 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.