I am trying to write a program to check to see if a url exists or not. I did something similar in VBA using the GetRemoteFile method. Is there something in Visual Lisp that I can use?
|
I am trying to write a program to check to see if a url exists or not. I did something similar in VBA using the GetRemoteFile method. Is there something in Visual Lisp that I can use?
Hi
ExampleCode:(defun download(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 "\nUnable to move the file \"" (strcat (vl-filename-base cp)(vl-filename-extension cp)) "\" since the directory \n\"" tmp ) (vl-file-delete tmp) ) (progn (vl-file-delete tmp) (if (zerop (vl-file-size cp)) (progn (vl-file-delete cp) (princ "\nUnable to download the file.") ) (setq ok T) ) ) ) ) ) (princ "\nThe url is not valid.") ) ok )
If OK, return TCode:(download "http://carnet-de-cablage.chez-alice.fr/Lisp/Gef.zip" "c:/test/")
An another with activex
@+Code:(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) )
Thank you Patrick for the response to my question. Now this posses another question that I have. I am using Acad 2002 and I am going through the help files looking for the "vla" functions and there are none listed, there are only "vl" ,"vlax", and "vlr" functions. Are "vla" functions something that was introducted to Acad after the 2002 verison?
From the Developer Help: AutoLisp Developer's Guide --> Using the Visual LISP Environment --> Working with ActiveX --> Using Visual LISP functions with ActiveX methods
This explains the idea behind vla functions.
If you have access to the Autodesk University content (either for Autodesk University for older content from AUGI), there's a class I held on ActiveX from Lisp which covers how you translate the VBA object model into Lisp code. Here's the link to the older AU content hosted by AUGI...
http://www.augi.com/education/auhand...002/CP31-1.pdf
The Class i did the last copule years at AU covered the same information and is esentially the same although I added other non ActiveX topics like recursion and reactors in the newer classes.
The above link should give you what you are looking for.
Thank you very much Darren for the link to the document. I am trying to figure out how to pass a Lisp variable to a Vlisp string. I understand that when you are dealing with autocad entities with Lisp and you need to access them using Vlisp you need to convert them to an object before being able to work with them using any "vla-" functions using (vlax-ename->vla-object. I am creating a URL by concantinating a couple of different Lisp variables then I want to pass the completed URL string to the "vla-getremotefile" function to copy a dwf from the web. Can anyone point me in the right direction?
Thanks for the help.Code:(setq baseurl "http://www-go.sce.com/fim/images/") (setq dprefix(getvar "dwgprefix")) (setq distnum(substr dprefix 8 2)) (setq dwgname(vl-filename-base(getvar "dwgname"))) (setq url (strcat baseurl distnum "/" dwgname ".dwf")) (vla-GetRemoteFile url, true)
Moderator Note:
Last edited by Opie; 2008-08-07 at 02:05 PM. Reason: [CODE] tags added, see Moderator Note
You're correct, but it's reasonably simple. You convert the ename to a vla-object. The ename is what's returned in entsel or ssname (from a selection set). The same thing you use when getting the entity's data with entget.
So you basically have something like:
Then add the hyperlink to the hyperlinks collection through the vla-Add function:Code:(setq ename (entsel "Select entity to add hyperlink to:")) (setq objref (vlax-ename->vla-object (car ename)))Where:Code:(setq hypcol (vla-get-Hyperlinks objref)) (vla-Add hypcol url hdescr hloc)
- url is URL (wierdly named Hyperlink Name in the ActiveX code)
- hdescr is the text displayed in the tooltip while hovering the cursor over the entity
- hloc is only used to open sav a particular view of a drawing. e.g. open the drawing in Model space then set this to ",Model". Otherwise leave as empty string ""