Author Topic: file downloading with Vlisp  (Read 4563 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28682
file downloading with Vlisp
« on: September 22, 2003, 12:40:15 PM »
Code: [Select]
;;; FUNCTION
;;; downloads a file specified by a URL
;;; could be used to update a custom program or about
;;; 100 different things
;;;
;;; ARGUMENTS
;;; strURL = valid URL
;;; i.e.  "http://www.myfiles.com/README.txt"
;;;
;;; USAGE
;;; (MST-GetFileFromURL "http://www.theswamp.org/lilly.pond/public/GetFileFromURL.txt")
;;;
;;; PLATFORMS
;;; 2000+
;;;
;;; AUTHOR
;;; Copyrightę 2003 Mark S. Thomas
;;; mark.thomas@theswamp.org
;;;
;;; VERSION
;;; 0.9 Mon Sep 22, 2003
;;;
;;; NOTE
;;; if somebody gets this to work for a UNC name I want to see it, please
(defun MST-GetFileFromURL (strURL / vlUtilObj RemoteFile TmpFile strNewFile
                                  strFileBase strFileExt NewFile)

  (setq vlUtilObj
        (vla-get-Utility
          (vla-get-ActiveDocument
            (vlax-get-acad-object)
            )
          )
        )

  (setq RemoteFile
        (vl-catch-all-apply
          'vlax-invoke-method
          (list
            vlUtilObj
            'GetRemoteFile
            strURL
            'TmpFile
            :vlax-false
            )
          )
        )

  (if
    (vl-catch-all-error-p RemoteFile)
    (alert "Remote file not found, contact author of this program")
    ; else
    (progn
      (setq strFileBase (vl-filename-base TmpFile)
            strFileExt (vl-string-left-trim "."(vl-filename-extension TmpFile))
            strNewFile (strcat (vl-filename-base TmpFile)(vl-filename-extension TmpFile))
            )
      ); progn
    ); if

  (if strNewFile
    (setq NewFile
          (getfiled "Save File To:" strNewFile strFileExt 1)
          )
    )

  (if
    (not (vl-file-copy TmpFile NewFile nil))
    (alert "There was a problem saving the file, make sure a duplicate does not exist")
    ; else
    (vl-file-copy TmpFile NewFile nil)
    ); if

  (prompt
    (strcat "\nOriginal downloaded file = "TmpFile)
    )

  (princ)
  ); defun
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28682
file downloading with Vlisp
« Reply #1 on: September 22, 2003, 01:12:57 PM »
better, read the header
Code: [Select]
;;; FUNCTION
;;; downloads a file specified by a URL
;;; could be used to update a custom program or about
;;; 100 different things
;;;
;;; ARGUMENTS
;;; strURL = valid URL
;;; i.e.  "http://www.myfiles.com/README.txt"
;;;
;;; USAGE
;;; (MST-GetFileFromURL "http://www.theswamp.org/lilly.pond/public/GetFileFromURL.txt")
;;;
;;; PLATFORMS
;;; 2000+
;;;
;;; AUTHOR
;;; Copyrightę 2003 Mark S. Thomas
;;; mark.thomas@theswamp.org
;;;
;;; VERSION
;;; 0.9 Mon Sep 22, 2003
;;; 0.95 Mon Sep 22, 2003
;;;
;;; NOTE
;;; valid and non valid URL's
;;; (vla-IsURL utilobj "\\DPW\SYS\USERS\PW2N\file.txt"):vlax-false
;;; (vla-IsURL utilobj "C:\\temp\Text Document.txt"):vlax-false
;;; (vla-IsURL utilobj "file://C:\\temp\Text Document.txt"):vlax-true
;;; (vla-IsURL utilobj "file://\\DPW\SYS\USERS\PW2N\file.txt"):vlax-true
(defun MST-GetFileFromURL (strURL / vlUtilObj RemoteFile TmpFile strNewFile
                                  strFileBase strFileExt NewFile)
  (setq vlUtilObj
        (vla-get-Utility
          (vla-get-ActiveDocument
            (vlax-get-acad-object)
            )
          )
        )

  (if
    (and
      (= (type strURL) 'STR)
      (= (vla-IsURL vlUtilObj strURL) :vlax-true)
      )
    (setq RemoteFile
          (vl-catch-all-apply
            'vlax-invoke-method
            (list
              vlUtilObj
              'GetRemoteFile
              strURL
              'TmpFile
              :vlax-false
              )
            )
          )
    ); if

  (if
    (vl-catch-all-error-p RemoteFile)
    (alert "Remote file not found, contact author of this program")
    ; else
    (progn
      (setq strFileBase (vl-filename-base TmpFile)
            strFileExt (vl-string-left-trim "."(vl-filename-extension TmpFile))
            strNewFile (strcat (vl-filename-base TmpFile)(vl-filename-extension TmpFile))
            )
      ); progn
    ); if

  (if strNewFile
    (setq NewFile
          (getfiled "Save File To:" strNewFile strFileExt 1)
          )
    )

  (if
    (not (vl-file-copy TmpFile NewFile nil))
    (alert "There was a problem saving the file, make sure a duplicate does not exist")
    ; else
    (vl-file-copy TmpFile NewFile nil)
    ); if

  (prompt
    (strcat "\nOriginal downloaded file = "TmpFile)
    )

  (princ)
  ); defun

;;; Last change: 2003 Sep 22
;;; Timestamp: <MST-GetFileFromURL.lsp Mon 2003/09/22 13:10:17  PC16883>
;;; vim:tw=78:ts=4:
TheSwamp.org  (serving the CAD community since 2003)