Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Visual Lisp Help - Check if URL Exists

  1. #1
    Member caddog71's Avatar
    Join Date
    2007-02
    Location
    Paramount, California
    Posts
    35
    Login to Give a bone
    0

    Question Visual Lisp Help - Check if URL Exists

    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?

  2. #2
    Member
    Join Date
    2008-07
    Posts
    19
    Login to Give a bone
    0

    Default Re: Visual Lisp Help - Check if URL Exists

    Hi

    Code:
    (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
    )
    Example
    Code:
    (download "http://carnet-de-cablage.chez-alice.fr/Lisp/Gef.zip" "c:/test/")
    If OK, return T

    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)
    )
    @+

  3. #3
    Member caddog71's Avatar
    Join Date
    2007-02
    Location
    Paramount, California
    Posts
    35
    Login to Give a bone
    0

    Question Re: Visual Lisp Help - Check if URL Exists

    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?

  4. #4
    Certifiable AUGI Addict irneb's Avatar
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Visual Lisp Help - Check if URL Exists

    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.
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

  5. #5
    Login to Give a bone
    0

    Default Re: Visual Lisp Help - Check if URL Exists

    Quote Originally Posted by caddog71 View Post
    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?
    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.

  6. #6
    Member caddog71's Avatar
    Join Date
    2007-02
    Location
    Paramount, California
    Posts
    35
    Login to Give a bone
    0

    Default Re: Visual Lisp Help - Check if URL Exists

    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?


    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)
    Thanks for the help.

    Last edited by Opie; 2008-08-07 at 02:05 PM. Reason: [CODE] tags added, see Moderator Note

  7. #7
    Certifiable AUGI Addict irneb's Avatar
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Visual Lisp Help - Check if URL Exists

    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:
    Code:
    (setq ename (entsel "Select entity to add hyperlink to:"))
    (setq objref (vlax-ename->vla-object (car ename)))
    Then add the hyperlink to the hyperlinks collection through the vla-Add function:
    Code:
    (setq hypcol (vla-get-Hyperlinks objref))
    (vla-Add hypcol url hdescr hloc)
    Where:
    • 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 ""
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

  8. #8
    Certifiable AUGI Addict irneb's Avatar
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Visual Lisp Help - Check if URL Exists

    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:
    Code:
    (setq hyp (vla-Add hypcol "http://www-go.sce.com/fim/images/" "test" 
    ""))
    ;; Then display the object
    (vlax-dump-object hyp)
    This gave:
    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 = ""
    So then I tried the following:
    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"
    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")
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

  9. #9
    Member caddog71's Avatar
    Join Date
    2007-02
    Location
    Paramount, California
    Posts
    35
    Login to Give a bone
    0

    Default Re: Visual Lisp Help - Check if URL Exists

    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

  10. #10
    All AUGI, all the time
    Join Date
    2015-12
    Location
    Central Oregon
    Posts
    591
    Login to Give a bone
    0

    Default Re: Visual Lisp Help - Check if URL Exists

    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.
    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)
    )
    Hope that helps a bit,
    Jeff

Page 1 of 2 12 LastLast

Similar Threads

  1. visual lisp editor should be like visual studio
    By Wish List System in forum AutoCAD Wish List
    Replies: 1
    Last Post: 2011-11-17, 05:33 PM
  2. Programacion en Lisp y Visual Lisp
    By ralmavar in forum Español - AutoCAD / AutoCAD LT
    Replies: 7
    Last Post: 2009-06-15, 01:52 PM
  3. Replies: 2
    Last Post: 2008-02-01, 09:05 PM
  4. Check if Custom Drawing Property exists
    By ccowgill in forum AutoLISP
    Replies: 9
    Last Post: 2007-08-29, 01:07 PM
  5. Check to see if file exists
    By ccowgill in forum AutoLISP
    Replies: 11
    Last Post: 2006-04-10, 09:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •