TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Patrick_35 on February 23, 2007, 05:22:11 AM
-
Hello,
How download a link without Dialog Box and without use SendKey ?
I try
(setq shell (vlax-create-object "Shell.Application"))
(vlax-invoke shell 'open "http://carnet-de-cablage.chez-alice.fr/Lisp/Rbloc.zip")
(vlax-release-object shell)
And
(setq ie (vlax-Create-Object "InternetExplorer.Application"))
(vlax-invoke ie 'navigate "http://carnet-de-cablage.chez-alice.fr/Lisp/Rbloc.zip")
(vlax-release-object ie)
but i have the dialog box :-(
Thanks
-
see code VBA...
Save Internet File using XMLHTTP Object (http://vbaexpress.com/kb/getarticle.php?kb_id=799)
-
What about ``GetRemoteFile''.
GetRemoteFile URL, LocalFile, IgnoreCache
-
Excel ElpanovEvgeniy: -)
I thus arrive at well translating into vlisp, but how to write the response into binary :?
'Create local file and save results to it
vFF = FreeFile
If Dir(vLocalFile) <> "" Then Kill vLocalFile
Open vLocalFile For Binary As #vFF
Put #vFF, , oResp
Close #vFF
Se7en, I will make a research with regard to ``GetRemoteFile''.
Thank you with you two :-)
@+
-
This used to work ...
(defun mst-activate (/ key)
(setq key (MST-GetFileFromURL
"http://www.theswamp.org/lilly.pond/public/key.txt"
)
)
(if key
(alert
(strcat
"Thank you for being my beta tester\n Make note of this number -> "
key
)
)
)
(princ)
)
(defun MST-GetFileFromURL (strURL / fo key vlUtilObj RemoteFile TmpFile)
(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 (not (vl-catch-all-error-p RemoteFile))
(if (setq fo (open TmpFile "r"))
(if (setq key (read-line fo))
(close fo)
)
)
)
(if (vl-file-delete TmpFile)
key
)
)
(mst-activate)
-
Great Mark
Thank you very much :-)
@+
-
For the pleasure, and in spite of the great solution of Mark, I continued with the ElpanovEvgeniy proposal but a problem arises. How to write in a file the character Null (chr 0) ?
Thanks in advance
@+
-
For the pleasure, and in spite of the great solution of Mark, I continued with the ElpanovEvgeniy proposal but a problem arises. How to write in a file the character Null (chr 0) ?
Thanks in advance
@+
Hi Patrick_35 :-)
This code writes to a file of 100 lines on 8 (chr 0)
(setq f(open "d:\\test.txt" "w"))
(repeat 100
(WRITE-LINE (VL-LIST->STRING '(0 0 0 0 0 0 0 0)) f)
)
(close f)
-
Thank you Evgeniy :-)
I'm there almost what I don't understand, this is why when I open the zip and that I look at the files, those are empty :?
(defun download (url dir / byte fic file http tbl)
(setq http (vlax-create-object "MSXML2.XMLHTTP"))
(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 (open file "w") n 0)
(foreach byte tbl
(if (eq byte 0)
(princ (vl-list->string '(0)) fic)
(write-char byte fic)
)
)
(close fic)
(vlax-release-object http)
(princ)
)
(download "http://carnet-de-cablage.chez-alice.fr/Lisp/Latt.zip" "c:/")
@+
-
Thank you Evgeniy :-)
I'm there almost what I don't understand, this is why when I open the zip and that I look at the files, those are empty :?
(defun download (url dir / byte fic file http tbl)
(setq http (vlax-create-object "MSXML2.XMLHTTP"))
(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 (open file "w") n 0)
(foreach byte tbl
(if (eq byte 0)
(princ (vl-list->string '(0)) fic)
(write-char byte fic)
)
)
(close fic)
(vlax-release-object http)
(princ)
)
(download "http://carnet-de-cablage.chez-alice.fr/Lisp/Latt.zip" "c:/")
@+
Hello Patrick.
On my computer, this code works! :)
-
(while (not (eq (vlax-get http 'readyState) 4))
(repeat 100)
)
If express established, such variant will load less processor...
(while (not (eq (vlax-get http 'readyState) 4))
(if acet-sys-sleep
(acet-sys-sleep 5);;(acet-sys-sleep [time-pause-msec])
(repeat 100)
)
)
-
Thank you Evgeniy :-)
I'm there almost what I don't understand, this is why when I open the zip and that I look at the files, those are empty :?
(defun download (url dir / byte fic file http tbl)
(setq http (vlax-create-object "MSXML2.XMLHTTP"))
(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 (open file "w") n 0)
(foreach byte tbl
(if (eq byte 0)
(princ (vl-list->string '(0)) fic)
(write-char byte fic)
)
)
(close fic)
(vlax-release-object http)
(princ)
)
(download "http://carnet-de-cablage.chez-alice.fr/Lisp/Latt.zip" "c:/")
@+
Hello Patrick.
On my computer, this code works! :)
Good idea with express 8-)
but the code works in my computer to
But if you launch the zip and extract the files, they're empty :?
@+
-
but the code works in my computer to
But if you launch the zip and extract the files, they're empty :?
@+
All works for me! :-)
-
Thanks Evgeniy
I don't understand. :-(
It's a windows version ? . I work with Xp Professional.
@+
-
Thanks Evgeniy
I don't understand. :-(
It's a windows version ? . I work with Xp Professional.
@+
I too use XP Professional +SP2 (ru)
The program checked for AutoCAD 2007 +SP1 (en)
-
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:/
-
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.
-
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 ?
@+
-
It's good. I found how to do it :-)
(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)
(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
)
@+