; BB - Batch Bind ; By Brian Forbes - http://www.autolisp.org/ ; Free consulting and custom lisps!! ; ; Permissions: ; Permission is hereby granted to copy and modify this lisp. It is provided "as is" by the author. ; The authorship and url must remain with the copied function. ; Version: ; 1.0 - April 2, 2004 ; Explanation: ; This function binds external refrences in a directory and copies it to a specified location within ; that same directory. ; To initiate the function, load bb.lsp and type bb. When the dialog closes, the function should open the ; first in the list of files selected, saveas to a specified location, and bind it. It will continue ; this process until halted (esc) or all the files have been processed. If the process has been halted, ; the function will continue when the process is started(*) again. After being halted and started from a ; new location, if the next file is not found, the registry should be cleared of the queued files. ; * To start the process after a file is opened, the bb.lsp needs to be loaded. This can either be ; done manually or by setting AutoCAD to load the lisps with every drawing. ; Known bugs: ; none ; This version has not been tested on the newer versions of AutoCAD. I'm not sure anyone actually uses it. ; If you want an updated copy, please email me. job @autolisp .org (setq bb_keydir "HKEY_LOCAL_MACHINE\\SOFTWARE\\Autodesk\\AutoCAD\\autolisp.org\\bb\\") (defun clear_bb (/ quant count) ; by Brian Forbes - http://www.autolisp.org/ - for use with batch bind (setq quant (vl-registry-read bb_keydir "quantity")) (setq count (atoi (if quant quant ""))) (vl-registry-write bb_keydir "quantity" "0") (while (>= (setq count (1- count)) 0) (if (vl-registry-read bb_keydir (itoa count)) (vl-registry-delete bb_keydir (itoa count)))) count ) (defun c:bb ( / quitmode pre dir fo a dcl count togglelst) ; Batch Bind ; by Brian Forbes - http://www.autolisp.org/ - donations welcome (setq maxcol 25) (clear_bb) (setq continue T) (if (not (= (getvar "sdi") 1)) (progn (alert "This function must be run in SDI mode. Please set SDI to 1.") (setq continue nil quitmode 1))) (while continue (setq pre (getvar "dwgprefix")) (setq dcl (strcat pre "bbout.dcl")) (setq dir (vl-directory-files pre "*.dwg")) (setq continue nil) (setq fo (open dcl "w")) (write-line "bb : dialog {" fo) (write-line (strcat " label = \"Batch Bind - bind a whole directory\"" (chr 59)) fo) (write-line (strcat " : row { key = \"r1\"" (chr 59)) fo) (write-line (strcat " : column { key = \"c1\"" (chr 59)) fo) (write-line (strcat " : button { key = \"butt1\"" (chr 59)) fo) (write-line (strcat " label = \"Unselect All\"" (chr 59)) fo) (write-line (strcat " }") fo) (write-line (strcat " : button { key = \"butt2\"" (chr 59)) fo) (write-line (strcat " label = \"Select All\"" (chr 59)) fo) (write-line (strcat " }") fo) (setq count -1) (foreach a dir (setq count (1+ count)) (if (> (length dir) maxcol) (if (and (> count 0) (= (rem count maxcol) 0)) (progn (write-line "} " fo) ; col (write-line (strcat ": column { key = \"c" (itoa count) "\"" (chr 59)) fo) )) ) ; if & progn maxcol (write-line (strcat " : toggle { key = \"t" (itoa count) "\"" (chr 59)) fo) (write-line (strcat " label = \"" a "\"" (chr 59)) fo) (write-line (strcat " }") fo) ) ; foreach (setq count2 (1+ count)) (write-line (strcat " }") fo) ; column1 (write-line (strcat " }") fo) ; r1 (write-line (strcat " ok_cancel_help" (chr 59)) fo) (write-line "}" fo) (close fo) (new_dialog "bb" (setq load_err (load_dialog dcl))) (if (> (length dir) 60) (progn (princ " Put some of these files in folders, there's too many!") (setq load_err -1))) (vl-file-delete dcl) (if (< load_err 0) (quit)) (action_tile "butt1" "(setq togglelst nil)(setq count -1)(foreach a dir (setq count (1+ count))(set_tile (strcat \"t\" (itoa count)) \"\"))") (action_tile "butt2" "(setq count -1) (while (< (setq count (1+ count)) (length dir)) (setq togglelst (append togglelst (list count))))(setq count -1)(foreach a dir (setq count (1+ count))(set_tile (strcat \"t\" (itoa count)) \"1\"))") (action_tile "cancel" "(done_dialog)(setq quitmode 1)") (action_tile "help" "(done_dialog)(princ \"Help\")(setq quitmode 2)") (setq count (1+ count)) (while (>= (setq count (1- count)) 0) (action_tile (strcat "t" (itoa count)) (strcat "(if (member " (itoa count) " togglelst) (setq togglelst (vl-remove " (itoa count) " togglelst)) (setq togglelst (append togglelst (list " (itoa count) "))))" ) ; strcat ) ; action_tile ) ; while (start_dialog) ) ; while continue (cond ((= quitmode 1) (princ "* CANCEL *")) ((= quitmode 2) (princ "? There's no help for you. Try someone with a little more patience. You're ugly. ")) (T (vl-registry-write bb_keydir "quantity" (itoa (length dir))) (setq count -1) (foreach a dir (setq count (1+ count)) (if (member count togglelst) (vl-registry-write bb_keydir (itoa count) a) ) ; if member ) ; foreach (institute_bb nil) ) ; T cond ) ; cond (princ) ) ; bb (defun institute_bb (go / quant count pre curdwg file) ; for use with bb ; by Brian Forbes - http://www.autolisp.org/ ; implimentation of the bb command (setq quant (atoi (vl-registry-read bb_keydir "quantity")) count -1) (setq pre (getvar "dwgprefix") innerfolder "bound\\") (while (and (<= (setq count (1+ count)) quant) (not curdwg) (> quant 0)) (setq curdwg (vl-registry-read bb_keydir (itoa count))) ) (if curdwg (setq file (findfile (strcat pre curdwg))) (progn (clear_bb) (command "_saveas" "" (strcat pre innerfolder (getvar "dwgname")) "xref" "bind" "*" "_qsave") ) ; progn ) (if file (progn (vl-mkdir (strcat pre innerfolder)) (vl-registry-delete bb_keydir (itoa (1- count))) (if go (command "_saveas" "" (strcat pre innerfolder (getvar "dwgname")) "xref" "bind" "*" "_qsave" "open" file) (command "_qsave" "open" file) ) ; if ) (clear_bb)) ; if & progn (princ) ) ; institute_bb (if (> (atoi (vl-registry-read bb_keydir "quantity")) 0) (institute_bb 1))