Author Topic: Help with Opening, Saving and Closing a File using LISP  (Read 1299 times)

0 Members and 1 Guest are viewing this topic.

cmwade77

  • Swamp Rat
  • Posts: 1206
Help with Opening, Saving and Closing a File using LISP
« on: May 07, 2009, 07:31:21 PM »
Ok, I am having some major problems with opening, saving and closing files.

Code: [Select]
;This first function is from another website, unfortunately I forgot to write down where I found it, so if it looks familar to you, please let me know and I will add the proper credit.
(defun OpenFile(FilePath Activate / oFile)
  (vl-load-com) 
  (if (findfile FilePath)
    (if (vl-file-systime FilePath)
     (if
       (vl-catch-all-error-p
        (setq oFile
  (vl-catch-all-apply
   'vla-open
     (list
       (vla-get-Documents
        (vlax-get-acad-object)) FilePath))))
      (alert
(strcat "ERROR.\n Can't open file: " FilePath))
      (if Activate(vla-Activate oFile))
      ); end if
     (alert
       (strcat "ERROR. File " FilePath
       "\n may be opened, inaccessible or password protected."))
    ); end if
  (alert
    (strcat "ERROR.\n File not found: " FilePath))
  ); end if
oFile
); end of OpenFile



(defun c:tst (); This routine is to open each file.

(setq images (dos_dir (strcat (dos_getdir "" "h:\\BEI-TEMP\\" "Select the folder with the backgrounds that need to be cleaned up:" T) "*.dwg") 1))
(if (/= rpt nil)
(progn
(if (< a (+ rpt 1))
(progn
(setq FileString (strcat pth (nth (- a 1) images)))
(setq a (+ a 1))
(OpenFile FileString T)

)
(progn
(setq rpt nil)
)
)
)
)
)


(defun c:RunAtDocumentLoad () ;This routine will have everything in it that will run when the document loads, this version of it causes AutoCAD to completely crash.
        (vl-cmdf "._QSAVE")
(vl-cmdf "._close")

)

(defun c:RunAtDocumentLoad () ;This routine will have everything in it that will run when the document loads, this version does not actually close the files for some reason.       
(vla-close (vla-get-documents (vlax-get-acad-object)) :vlax-true)
)

Please note that I am doing this with OpenDCL, and the routines are run on document activation.