AfraLisp Blog

The AutoLisp/Visual Lisp/VBA Resource Website

AfraLisp Blog

Home Newsletter Utter Rubbish Coding Tips AutoCAD Tips Contact Downloads WAUN

DOSLib - Batch Slide Application

In this application we are going to use some of the DOSLib functions to Convert a selection of drawings to slides. I've explained the program within the coding by including comments for each line. Good luck and here we go... 

(defun c:batchslide ( / CNTR DPATH DWGPATH FILE1 FLAG FLEN FNAME
                        FNAME1 LEN1 MESSAGE NFILES NFILES1 SCRFILE
                        UFILES)

;;;Firstly we need to check if DOSLib is loaded.
	(cond
	  ((= (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"))))
	);cond
;;;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.

;;;We must now check that, if we are using A2K, Single Document
;;;Mode is switched OFF.

	(if (= (atoi (substr (getvar "acadver") 1 2)) 15)
	;if A2K
		(setvar "sdi" 0)
		;switch off single document interface

	);if

;;;Now we are going to do a bit of advertising and display a
;;; Splash Screen for about 5 seconds.

	(dos_splash "afralisp.bmp" 5)
	;display the splash screen

;;;Now, we need to retrieve the names of the files that we would
;;;like to make slides from.

	(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)
		;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 Slides" 4 4))
	;display the message box

	(if (= flag 6)
	;if Yes selected

	(progn
	;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
		;drawing.

		(setq flen (strlen fname))
		;get the length of file name

		(setq len1 (- flen 4))
		;take away the last 4 characters (.DWG)

		(setq fname1 (substr fname 1 len1))
		;get just the filename without the extension.
		;"fname1" will be used as our slide file name.

;;;write the commands to the script file

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

		(write-line (strcat ".zoom" " e") file1)
		;zoom to extents
		;write it to the script file

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

		(write-line (strcat "mslide " fname1) file1)
		;make the slide
		;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

		(if (= (atoi (substr (getvar "acadver") 1 2)) 15)
		;if A2K
		
		(write-line "close" file1)
		;close the drawing
		;write it to the script file

		);if

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

	);repeat

;;;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.

	);progn

	);if

 (princ)

);defun

(princ)

The script file, batdir.scr should look something like this : 
open O:\E51D\E51D1\temp\L102.dwg
.zoom e
filedia 0
mslide O:\E51D\E51D1\temp\L102
filedia 1
qsave
close  (A2K Only)
open O:\E51D\E51D1\temp\L101.dwg
.zoom e
filedia 0
mslide O:\E51D\E51D1\temp\L101
filedia 1
qsave
close  (A2K Only)

To download this application, Click Here.

Click here to download the latest version of DOSLib.

Click here to visit Robert Mcneel and Associates.

 
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