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 ""
One strange thing though: if you don't pass a NamedLocation to the vla-Add function, then the Description is ignored. E.g. I did the following:This gave:Code:(setq hyp (vla-Add hypcol "http://www-go.sce.com/fim/images/" "test" "")) ;; Then display the object (vlax-dump-object hyp)So then I tried the following:Code:; IAcadHyperlink: A URL and URL description ; Property values: ; Application (RO) = #<VLA-OBJECT IAcadApplication 00d74d3c> ; URL = "http://www-go.sce.com/fim/images/" ; URLDescription = "" ; URLNamedLocation = ""As you can see the created hypelink passes the Location as the Description. So If you want to use a description, then obtain a ref of the created hyperlink as done in my examples (setq hyp (vla-Ad ...)). Then set that hyperlink's values, e.g. (vla-put-URLDescription hyp "Name to show")Code:Command: (setq hyp (vla-Add hypcol "http://www-go.sce.com/fim/images/" "test" "testing")) #<VLA-OBJECT IAcadHyperlink 34181a5c> Command: (vlax-dump-object hyp) ; IAcadHyperlink: A URL and URL description ; Property values: ; Application (RO) = #<VLA-OBJECT IAcadApplication 00d74d3c> ; URL = "http://www-go.sce.com/fim/images/" ; URLDescription = "testing" ; URLNamedLocation = "testing"
Thank you for the responses to my thread but I still don't understand on how to make the "vla-getremotefile" function work. Help please.
Code:(defun c:learn () (setq baseurl "http://www-go.sce.com/fim/images/") (setq dwgname(vl-filename-base(getvar "dwgname")));Get drawing name without extension (setq dprefix(getvar "dwgprefix")) (setq distnum(substr dprefix 8 2)) (setq web (strcat baseurl distnum "/" dwgname ".dwf")) (setq urlobj (vlax-make-safearray vlax-vbstring '(0 . 0))) (vlax-safearray-put-element urlobj 0 web) (vlax-safearray->list urlobj) (vla-getremotefile (urlobj)) )
Last edited by Opie; 2008-08-12 at 02:00 AM. Reason: [code] tags added
Hi caddog71,
You don't need to use safearrays and what-nots when passing basic string arguments. You also must study what it is the Method is expecting, and what object it must be called from.
In this case, the GetRemoteFile is a method of the Utility Object of the current drawing. It MUST be passed all 3 arguments, the URL to get, an empty variable that will hold the temporary file name, and a true/false of whether to download the file even if it was already downloaded in this session. That being said, this should work or be real close....I don't have anything to test this with right now.
Hope that helps a bit,Code:(defun c:learn (/ BASEURL DISTNUM DOC DPREFIX DWGNAME UTIL WEB) (setq baseurl "http://www-go.sce.com/fim/images/") (setq dwgname(vl-filename-base(getvar "dwgname")));Get drawing name without extension (setq dprefix(getvar "dwgprefix")) (setq distnum(substr dprefix 8 2)) (setq web (strcat baseurl distnum "/" dwgname ".dwf")) (setq doc (vla-get-activedocument (vlax-get-acad-object)) util (vla-get-utility doc) ) (vla-getremotefile util web 'destination :vlax-true) (princ) )
Jeff