I created a LISP routine that will redefine all my dynamic blocks and regular blocks within a drawing. I set up a SCRIPT to do a batch run of this routine across several drawings. The LISP routine I created works great by itself, but when I run it within a SCRIPT AutoCAD's Help get's pulled up and the script does not complete. I'm baffled by this....
A portion of the Script I'm using:
sdi 1
(defun C:redef(/ started b b1) (command "-purge" "a" "*" "N");;purges the drawing (command "-purge" "a" "*" "N");;purges the drawing (layerstate-save "DCSSpace" 239 nil) (command "-layer" "off" "*" "YES" "") (command "-layer" "on" "*eqpm*, *hvac*, *powr*" "") (c:blklist);;lisp routine (tblnext "block" T) (blkct);;lisp routine (tblnext "block" T) (command "-purge" "a" "*" "N");;purges the drawing (setq replacect 0) ;;sets replaced counter (while (setq b (tblnext "block" (if (not started) T))) (setq started T) (if (/= (substr (cdadr b) 1 1) "*") (progn (setq b1 (cdadr b)) (if (findfile (strcat "C:/SYMLIB/WBLOCKS/" b1 ".dwg")) ;;if file is in library replaces (progn (setq dwgname1 (getvar "dwgname")) (setq csv1(strcat dwgname1 "," b1)) (setq f (open "C:/SYMLIB/BlocksReplaced.txt" "A")) (write-line csv1 f) (close f) (command "insert" (strcat b1 "=C:/SYMLIB/WBLOCKS/" b1)) (command); cancel insertion after new definition imported (setq replacect (1+ replacect));;counter for defined blocks replaced ); end progn ); end if ); end progn ); end if ); end while (setq oldsrvc (ssget "X" '((8 . "*SRVC*")))) (setq oldcstr (ssget "X" '((8 . "*CSTR*")))) (command "erase" oldsrvc oldcstr "") (command "-purge" "a" "*" "N");;purges the drawing (command "-purge" "a" "*" "N");;purges the drawing (prompt (strcat "\nTotal defined blocks: " (itoa origblkct)));;total defined blocks (prompt (strcat "\nDefined blocks replaced: " (itoa replacect)));;blocks replaced final count (layerstate-restore "DCSSpace") (princ) ); end defun
Have you tried typing 'resume at the command line when that happens? If you can Isolate where it happens, you may be able to put the resume command in your script. Maybe turn on logs, read the files to see where it breaks.
Hi
1. each time you open a drawing you need to verify that your lisp loaded
otherwise you can not call it
2. there is no need to call your lisp function (c:redef)
REDEF is enough (like any other regular autocad command)
Moshe