vnk172004 Posted July 16, 2009 Posted July 16, 2009 As i said in the above title, I am looking for a lisp file which will open the latest dxf file from the pre-defined directory given in the lisp file. Is it possible to do so? Quote
Lee Mac Posted July 16, 2009 Posted July 16, 2009 When you say "Latest" do you mean the last one to be modified in a directory? Quote
vnk172004 Posted July 16, 2009 Author Posted July 16, 2009 Yes, you are right. Need to open latest modified drawing in the directory. Quote
Lee Mac Posted July 17, 2009 Posted July 17, 2009 This should open the lastest dwg file in a directory, I think you need to modify it to using vla-import to open the lastest dxf file. (defun c:open_last (/ path lst dwg) (vl-load-com) (if (setq path (Directory-Dia "Select Directory: ")) (progn (foreach dwg (mapcar (function (lambda (file) (strcat path file))) (vl-directory-files path "*.dwg" 1)) (setq lst (cons (list dwg (remove_nth (vl-file-systime dwg) 2)) lst))) (if (vl-catch-all-error-p (vl-catch-all-apply (function (lambda ( ) (vla-open (vla-get-Documents (vlax-get-acad-object)) (setq dwg (dSort lst)) :vlax-false))))) (princ (strcat "\n** " dwg " Failed to Open **")))) (princ "\n*Cancel*")) (princ)) (defun Directory-Dia (Message / sh folder folderobject result) ;; By Tony Tanzillo (vl-load-com) (setq sh (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application")) (setq folder (vlax-invoke-method sh 'BrowseForFolder (vla-get-HWND (vlax-get-Acad-Object)) Message 0)) (vlax-release-object sh) (if folder (progn (setq folderobject (vlax-get-property folder 'Self) result (vlax-get-property FolderObject 'Path)) (vlax-release-object folder) (vlax-release-object FolderObject) (if (/= (substr result (strlen result)) "\\") (setq result (strcat result "\\")) result)))) ; Stig (defun remove_nth (lst i / a) (setq a -1) (vl-remove-if (function (lambda (n) (= (setq a (1+ a)) i))) lst)) (defun dSort (lst / lst) (while (progn (cond ((not (vl-remove-if 'null (mapcar 'cadr lst))) (setq lst nil)) ((apply '= (vl-sort (mapcar 'caadr lst) (function (lambda (a b) (< a b))))) (setq lst (mapcar (function (lambda (x) (list (car x) (cdadr x)))) lst))) (t (setq lst (caar lst)) nil)))) lst) Quote
vnk172004 Posted July 17, 2009 Author Posted July 17, 2009 Hi Lee mac, Thanks for your reply But as i said earlier cant we include pre-defined directory path in the code? and can you modify it to open the dxf file Quote
Lee Mac Posted July 17, 2009 Posted July 17, 2009 I thought you might like my ObjectDBX Directory window... Quote
Lee Mac Posted July 17, 2009 Posted July 17, 2009 Try this: (defun c:open_last (/ path lst dwg) (vl-load-com) (setq Dir "C:\\") ;; <<--- Your "Pre-Defined Directory" goes here (if (vl-file-directory-p Dir) (progn (foreach dwg (mapcar (function (lambda (file) (strcat path file))) (vl-directory-files path "*.dxf" 1)) (setq lst (cons (list dwg (remove_nth (vl-file-systime dwg) 2)) lst))) (if (vl-catch-all-error-p (vl-catch-all-apply (function (lambda ( ) (vla-import (vla-get-ActiveDocument (vlax-get-acad-object)) (setq dwg (dSort lst)) (vlax-3D-point '(0 0 0)) 1.))))) (princ (strcat "\n** " dwg " Failed to Open **")))) (princ "\n*Cancel*")) (princ)) ; Stig (defun remove_nth (lst i / a) (setq a -1) (vl-remove-if (function (lambda (n) (= (setq a (1+ a)) i))) lst)) (defun dSort (lst / lst) (while (progn (cond ((not (vl-remove-if 'null (mapcar 'cadr lst))) (setq lst nil)) ((apply '= (vl-sort (mapcar 'caadr lst) (function (lambda (a b) (< a b))))) (setq lst (mapcar (function (lambda (x) (list (car x) (cdadr x)))) lst))) (t (setq lst (caar lst)) nil)))) lst) Quote
Cad64 Posted July 18, 2009 Posted July 18, 2009 How about just opening up your Explorer Window, browse to the specific directory and then click on the "Date Modified" tab. You can do the same thing within Autocad using the "Design Center". You can also use the sidebar in the Autocad "Open" dialog to store folders that you need to access on a regular basis. You can add job folders containing drawings you are currently working on, and remove ones that you are finished with. This is a real time saver for me and it's something that I don't think too many people are aware of. Quote
Lee Mac Posted July 18, 2009 Posted July 18, 2009 I thought this could be done another way, but i took it as a challenge Quote
Cad64 Posted July 18, 2009 Posted July 18, 2009 That's fine, but I think we should be offering practical answers using standard Autocad utilities or Windows functionality first, before diving into lisp. Lisp is great, and it can be a real lifesaver in some instances, but there are plenty of ways to do a lot of the things people are asking, that are already built into Autocad. I think people are relying a bit too much on lisp, and not learning the standard commands. If these guys ever go to work for a company that doesn't allow cutom routines, or if they have to work for a company that uses Autocad LT, they are going to be lost. Sorry, but that circle scaling lisp just got me going. I just don't understand why someone would request a lisp routine to scale a circle? Quote
Lee Mac Posted July 19, 2009 Posted July 19, 2009 I understand completely Rod. I am not too good at offering an alternative solution - many times I will miss the obvious answer. Basically because I don't use CAD from day to day, I just write the LISP, as I enjoy it. Quote
vnk172004 Posted July 21, 2009 Author Posted July 21, 2009 (defun c:open_last (/ path lst dwg) (vl-load-com) (setq Dir "C:\Acad_dwg\00109") (if (vl-file-directory-p Dir) (progn (foreach dwg (mapcar (function (lambda (file) (strcat path file))) (vl-directory-files path "*.dxf" 1)) (setq lst (cons (list dwg (remove_nth (vl-file-systime dwg) 2)) lst))) (if (vl-catch-all-error-p (vl-catch-all-apply (function (lambda ( ) (vla-import (vla-get-ActiveDocument (vlax-get-acad-object)) (setq dwg (dSort lst)) (vlax-3D-point '(0 0 0)) 1.))))) (princ (strcat "\n** " dwg " Failed to Open **")))) (princ "\n*Cancel*")) (princ)) ; Stig (defun remove_nth (lst i / a) (setq a -1) (vl-remove-if (function (lambda (n) (= (setq a (1+ a)) i))) lst)) (defun dSort (lst / lst) (while (progn (cond ((not (vl-remove-if 'null (mapcar 'cadr lst))) (setq lst nil)) ((apply '= (vl-sort (mapcar 'caadr lst) (function (lambda (a b) (< a b))))) (setq lst (mapcar (function (lambda (x) (list (car x) (cdadr x)))) lst))) (t (setq lst (caar lst)) nil)))) lst) I had modified directory path to this C:\Acad_dwg\00109 When I am using this lisp command it was showing *cancel* in command window. @Cad64 I am having 5 years of experience on cad. I know all the ways mentioned in your post and I am using that side bar method also for a long time. Actually my problem is I have to access multiple latest drawings from multiple folders for atleast 20-30 times a day. It was frustrating me by using normal file accessing methods. Quote
Lee Mac Posted July 21, 2009 Posted July 21, 2009 No problem in the LISP file. You need to specify a valid directory, for example: C:\\Acad_dwg\\00109\\ Using double backslashes Lee Quote
vnk172004 Posted July 21, 2009 Author Posted July 21, 2009 Sorry to bother you again. I tried with double backslashes also. Now it was showing the following error in command line ; error: bad argument type: stringp nil I am using acad2004, does the version has anything to do with this problem? Quote
Lee Mac Posted July 21, 2009 Posted July 21, 2009 Ok, that one was my fault There could be further errors as I haven't at all tested this LISP (defun c:open_last (/ Dir lst dwg) (vl-load-com) (setq Dir "C:\\") ;; <<--- Your "Pre-Defined Directory" goes here (if (vl-file-directory-p Dir) (progn (foreach dwg (mapcar (function (lambda (file) (strcat Dir file))) (vl-directory-files Dir "*.dxf" 1)) (setq lst (cons (list dwg (remove_nth (vl-file-systime dwg) 2)) lst))) (if (vl-catch-all-error-p (vl-catch-all-apply (function (lambda ( ) (vla-import (vla-get-ActiveDocument (vlax-get-acad-object)) (setq dwg (dSort lst)) (vlax-3D-point '(0 0 0)) 1.))))) (princ (strcat "\n** " dwg " Failed to Open **")))) (princ "\n*Cancel*")) (princ)) ; Stig (defun remove_nth (lst i / a) (setq a -1) (vl-remove-if (function (lambda (n) (= (setq a (1+ a)) i))) lst)) (defun dSort (lst / lst) (while (progn (cond ((not (vl-remove-if 'null (mapcar 'cadr lst))) (setq lst nil)) ((apply '= (vl-sort (mapcar 'caadr lst) (function (lambda (a b) (< a b))))) (setq lst (mapcar (function (lambda (x) (list (car x) (cdadr x)))) lst))) (t (setq lst (caar lst)) nil)))) lst) 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.