Originally Posted by
carl_hd_collins
I think I can infer from the ealier posts that there is a large number of drawings to be processed here, are they all in one directory? Abdul's program seems to work on this basis (correct me if I am wrong, please Abdul), are your drawings all in one place, or do you have the text file that lists out all their locations? It would not be too difficult to read the text file line by line and work in multiple folders.
Thanks for your feedback Collins. You are right. Here we go for a text file having the path\filename format.
Code:
(defun c:GenScr2 (/ wrkPath dwgList dwgName scrFile)
;;;
;;; This code assumes that you have a text file having file names including path
;;; i.e, C:\\PROJECTS\\PLOT\\DRAWING1.DWG
;;; If you wish to create a text file including path and sub folders, use the dir
;;; command at dos prompt (of the root folder of the drawings) as below:
;;; "DIR *.DWG /B /S /O >c:\work\DrawingList.txt"
;;; This will create a text file called DrawingList.txt in c:\work
;;;
;;; Better to assing a work folder
(setq wrkPath "C:\\Works\\")
;;;
;;; Now open the text file for reading
(setq dwgList (open (strcat wrkPath "DrawingList.txt") "r") ; substitute your path
scrFile (open (strcat wrkPath "Runme.scr") "w") ; open a script file
)
(while (setq dwgName (read-line dwgList)) ; loop till the end of file
;;;
;;; In case your path/file name contains spaces add the following line
;;; (Applicable for the previous code also)
(setq dwgName (strcat "\"" dwgName "\""))
(write-line ".Open" scrFile) ; write to script file
(write-line dwgName scrFile)
;;;If you need to load a lisp routine in each dwg load it here
(write-line "(load \"MyLispFile.Lsp\")" scrFile) ; load any required lisp routine
;;;
;;; Enter your commands here.
(write-line "MyCommand" scrFile)
;;;
;;; Preset the dxf file format before you proceed.
;;; May require minor modification depending on you
;;; AutoCAD version Notice the two spaces after dxfout
;;; in the following line acts like <enter>.This will
;;; accept the default file name and default format
(write-line ".Dxfout " scrFile)
;;; Better to save the drawing for uninterrupted scripting
(write-line ".Qsave" scrFile)
) ; while
(close dwgList)
(close scrFile) ; close when done
;;; Make sure that the current dwg won't prompt for
;;; save changes!
(command ".script" (strcat wrkpath "Runme.scr")) ; run the script
(princ)
) ; defun
Please note that I forgot to add quotation marks (") for the file names in the previous code posted. This is required if the path/file name contains spaces. Otherwise the script file will treat it as an <enter>. Substitute the following line instead of (setq dwgName (strcat dwgpath (nth count dwgList) )) in the previous code if somebody wish to use it:
Code:
(setq dwgName (strcat "\"" dwgpath (nth count dwgList) "\""))
Regards,
Abdul Huck