Author Topic: Download with vlisp  (Read 12304 times)

0 Members and 1 Guest are viewing this topic.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Download with vlisp
« Reply #15 on: February 26, 2007, 11:12:07 AM »
Unique my change:
(download "http://carnet-de-cablage.chez-alice.fr/Lisp/Latt.zip" "D:/")

add

I replase
"c:/" => " D:/"
I cannot write from the program to a root of disk C:/
« Last Edit: February 26, 2007, 11:15:02 AM by ElpanovEvgeniy »

fools

  • Newt
  • Posts: 72
  • China
Re: Download with vlisp
« Reply #16 on: March 01, 2007, 07:01:40 AM »
Patrick_35 's codes no work because of function write-char , (write-char 10 file) will write two chars to file -- 013(CR) & 010 (LF)
Use some HEX Editor open downloaded file , and change 0D 0A to 0A , downloaded file will be OK.
But i don't know how to only write HEX0A (LF)  to file.
« Last Edit: March 01, 2007, 07:03:34 AM by fools »
Good good study , day day up . Sorry about my Chinglish .

Patrick_35

  • Guest
Re: Download with vlisp
« Reply #17 on: March 01, 2007, 07:39:32 AM »
Thank you.
I noticed that my file actually made 7707 bytes and that with the writing by Write-char, princ, print or prin1, I found myself with a file of 7737 bytes, that is to say a difference in 30 bytes. I checked the size of my table which contains 7707 elements, therefore the size to be written well.  :?
The question
It's possible to write a file in binary with vlisp ?

@+

Patrick_35

  • Guest
Re: Download with vlisp
« Reply #18 on: March 01, 2007, 09:23:05 AM »
It's good. I found how to do it :-)
Code: [Select]
(defun download (url dir / byte fic file fso http tbl)
  (setq http (vlax-create-object "MSXML2.XMLHTTP")
        fso  (vlax-create-object "Scripting.FileSystemObject"))
  (vlax-invoke-method http 'open "get" url :vlax-false)
  (vlax-invoke http 'send)
  (while (not (eq (vlax-get http 'readyState) 4))
    (repeat 100)
  )
  (setq file (strcat dir (vl-filename-base url) (vl-filename-extension url))
tbl  (vlax-safearray->list (vlax-variant-value (vlax-get-property http 'responsebody)))
fic  (vlax-invoke fso 'CreateTextFile file))
  (foreach byte tbl
    (vlax-invoke fic 'write (vl-list->string (list byte)))
  )
  (vlax-invoke fic 'close)
  (vlax-release-object http)
  (vlax-release-object fso)
  (princ)
)

And with the solution of Mark (sorry it's in french)
Code: [Select]
(defun telecharger(lien rep / cp ok tmp util)
  (setq util (vla-get-Utility (vla-get-ActiveDocument (vlax-get-acad-object))))
  (if (eq (vla-isurl util lien) :vlax-true)
    (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-GetRemoteFile (list util lien 'tmp :vlax-true)))
      (princ "\nErreur lors du téléchargement.")
      (progn
(setq cp (strcat rep (vl-filename-base lien) (vl-filename-extension lien)))
(if (findfile cp)
  (vl-file-delete cp)
)
(if (vl-catch-all-error-p (vl-catch-all-apply 'vl-file-copy (list tmp cp)))
  (progn
      (princ "\nImpossible de déplacer le fichier \""
   (strcat (vl-filename-base cp)(vl-filename-extension cp))
   "\" depuis le répertoire \n\""
   tmp
    )
    (vl-file-delete tmp)
  )
  (progn
    (vl-file-delete tmp)
            (if (zerop (vl-file-size cp))
              (progn
(vl-file-delete cp)
(princ "\nImpossible de télécharger le fichier.")
      )
      (setq ok T)
    )
  )
)
      )
    )
    (princ "\nLe lien n'est pas valide.")
  )
  ok
)

@+