Small Fish Posted September 1, 2009 Posted September 1, 2009 Hi I have some code that I want to batch purge drawings, using doslib functions. It's not working and stops about half way. I suspect there may be more than one error. Can someone fix it please? ps I want to keep the doslib functions.- thanks (defun c:BatchPurge (/ UserFile UserCat DirPath FileList File#1 DwgName FileName) (vl-load-com) (setq DirPathdefault (getvar "dwgprefix"));Current folder (setq DirPath (dos_getdir "Browse for a Drawing folder" DirPathdefault "Select a folder to clean drawing files") ) (if (= DirPath nil) (exit) (setq DwgLst (vl-directory-files DirPath "*.dwg" 1));list of drawings in folder );if ;Create list of all *.dwg files in selected Directory (setq DwgtoCleanLst(dos_multilist "Select Files" "Select which Drawings to purge." DwgLst));list of drawings selected (setq File#1 (open "c:/Documents and Settings//rxbeeto0//BatchClean.scr" "w")) ;; open/make a scriptfile to write to (foreach DwgName DwgtoCleanLst (setq FileName (strcat "\"" DirPathdefault "\\" DwgName "\"")) (princ "open\n" FileName) (princ (strcat FileName "\n") FileName) (princ "purge\n" File#1) (princ "all\n\n" File#1) (princ "_.qsave\n" FileName) (princ "_.close\n" FileName) ) (close FileName) (command "script" "C:\\Documents and Settings\\rxbeeto0\\BatchClean.scr") (princ) );defun Quote
Small Fish Posted September 1, 2009 Author Posted September 1, 2009 thanks - but it still does not work. Quote
ronjonp Posted September 1, 2009 Posted September 1, 2009 I know you wanted to stick with doslib but I don't have it.. Here is something I put together when I first started writing code (my disclaimer for the "ugleeness"). it's suited me fine for many years. (defun c:batch (/ $value choice dir dwglist file fn fno id sel w x) (if (and (setq dir (getfiled "Select A Drawing File" (getvar 'dwgprefix) "dwg" ) (setq dir (vl-filename-directory dir)) (setq dwglist (mapcar '(lambda (x) (strcase (strcat dir '"\\" x) t)) (vl-directory-files dir "*.dwg") ) ) (setq dwglist (vl-sort dwglist '<)) (setq w (itoa (apply 'max (mapcar 'strlen (mapcar 'vl-filename-base dwglist))))) ) (progn (setq file (open (strcat (getenv "temp") "\\cleanup.scr") "w") fn (vl-filename-mktemp nil nil ".dcl") fno (open fn "w") ) (write-line (strcat "batch : dialog { label = \"RJP-Batch\"; :column { :boxed_column { label = \"< Select Drawings to Process >\"; : list_box { key = \"dwglist\"; height = 25; width = " w "; multiple_select = true; } } } : row { : button { label = \"&Select...\"; key = \"select\"; } : button { label = \"&Cancel\"; is_cancel = true; key = \"cancel\"; } } }" ) fno ) (close fno) (setq id (load_dialog fn)) (if (not (new_dialog "batch" id)) (exit) ) (start_list "dwglist") (mapcar 'add_list (mapcar 'vl-filename-base dwglist)) (end_list) (action_tile "dwglist" "(setq choice $value)") (action_tile "select" "(done_dialog)") (action_tile "cancel" "(setq choice nil)(done_dialog)(vl-file-delete fn)") (start_dialog) (unload_dialog id) (if (and choice (setq sel (mapcar (function (lambda (x) (nth x dwglist))) (read (strcat "(" choice ")")) ) ) ) (progn (foreach f sel (write-line (strcat "_.open \"" f "\"") file) (write-line "(repeat 3 (vla-purgeall (vla-get-activedocument (vlax-get-acad-object))))" file ) (write-line "_.qsave _.close" file) ) (close file) (command ".script" (strcat (getenv "temp") "\\cleanup.scr")) ) ) ) ) (princ) ) Quote
Small Fish Posted September 1, 2009 Author Posted September 1, 2009 Hey thanks Ronjonp for sharing that interesting piece of code. It works well. However I would still like to make make my code with the doslib functions work. Any ideas? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.