AfraLisp Blog

The AutoLisp/Visual Lisp/VBA Resource Website

AfraLisp Blog

Home Newsletter Utter Rubbish Coding Tips AutoCAD Tips Contact Downloads WAUN

;;;This application will Batch Bind All Xref's in a selection of drawings.
;;;Known Dependencies :
;;;DosLib must be available and within the AutoCAD Search Path.
;;;Doslib is available from Robert McNeel & Associates
;;;Single Drawing Interface must be ON. (setvar "SDI" 1)
;;;The current drawing loaded must be saved before running BatchBind.
;;;Written by Kenny Ramage
;;;March 2002

(prompt "\nBatchBind Ver 1.1 - Written by Kenny Ramage -")


;;;Firstly we need to check if DOSLib is loaded.
((= (atoi (substr (getvar "acadver") 1 2)) 13)
(if (not (member "doslib13.arx" (arx)))
(arxload (findfile "doslib13.arx"))))
((= (atoi (substr (getvar "acadver") 1 2)) 14)
(if (not (member "doslib14.arx" (arx)))
(arxload (findfile "doslib14.arx"))))
((= (atoi (substr (getvar "acadver") 1 2)) 15)
(if (not (member "doslib2k.arx" (arx)))
(arxload (findfile "doslib2k.arx"))))
;;;This, first checks the version of AutoCAD in use.
;;;It then checks to see if that version of Doslib is loaded.
;;;If it is not, it searches the AutoCAD search path for the
;;;relevant version, and then loads it.

;;;Now, we need to retrieve the names of the files that we would
;;;like to bind all xrefs.

(setq dwgpath (getvar "dwgprefix"))
;get the path to the current directory

(setq ufiles (dos_getfilem "Select Drawings"
dwgpath "Drawing Files (*.DWG)|*.DWG"))
;display the file dialogue box

(if (not ufiles)
;if no files selected or Cancel

;exit the application


;;;The first item in the list "ufiles" is the directory path
;;;The remaining items are the file names.
;;;First, let's retrieve the directory path.

(setq dpath (nth 0 ufiles))
;retrieve the directory path - the first item.

;;;Next, let's get the number of items in the list,
;;;and make sure that the user wants to continue.

(setq nfiles (length ufiles))
;get the length of the list

(setq nfiles1 (itoa (- nfiles 1)))
;count only the file names and convert to a string

(setq message (strcat "You have choosen " nfiles1 " files.
\nDo you want to continue?"))
;set up the message

(setq flag (dos_msgbox message "AfraLisp Batch Bind" 4 4))
;display the message box

(if (= flag 6)
;if Yes selected

;do the following

;;;We'll now open an external file to write our script to.

(setq scrfile (strcat dpath "batdir.scr"))
;add the path to the script file name

(setq file1 (open scrfile "w"))
;open the file to write

(setq cntr 1)
;set the counter

;;;We'll now start the loop, format the file names, and add
;;;the commands to the script file.

(repeat (- nfiles 1)
;start the loop

(setq fname (nth cntr ufiles))
;get the file name

(setq fname (strcat dpath fname))
;add the path to the file name.
;"fname" will be used to open each

;;;write the commands to the script file
;;;You can change this section to suit almost any type of batch script file
;;;that your imagination can come up with.

(write-line (strcat "open " fname) file1)
;open the drawing
;write it to the script file

(write-line (strcat "filedia" " 0") file1)
;switch off dialogues
;write it to the script file

(write-line (strcat "xref " "b " "*") file1)
;bind all xrefs
;write it to the script file

(write-line (strcat "filedia" " 1") file1)
;switch on dialogues
;write it to the script file

(write-line "qsave" file1)
;save the drawing
;write it to the script file

(setq cntr (1+ cntr))
;increment the counter


;;;now that we've finished writing the commands to the script
;;;file, we must remember to close it.

(close file1)
;close the script file

(command "script" scrfile)
;run the script file and sit back and have a beer.






The AutoLisp/Visual Lisp/VBA Resource Website

Copyright 1999-Perpetuity by AfraLisp

All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage

The AutoLisp/Visual Lisp/VBA Resource Website