Jump to content

Redefine specific block in drawing and save


Recommended Posts

Posted

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

Posted

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)

Posted

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

Posted

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.

Posted

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

  • 11 years later...
Posted (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 by Janouren
  • Like 1

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...