Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: Visual Lisp Help - Check if URL Exists

  1. #11
    Login to Give a bone
    0

    Default Re: Visual Lisp Help - Check if URL Exists

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

    Code:
    (defun c:test (/ objDOC objUTL locfile)
      (vl-load-com)
      (setq objDOC (vla-get-activedocument (vlax-get-acad-object)))
      (setq objUTL (vla-get-utility objDOC))
    
      (vla-getremotefile
        objUTL
        "http://www.uspconnectors.com/cad/product/hc520.dwg"
        'locfile
        :vlax-true
      )
    ;;;  (vl-catch-all-apply
    ;;;    (function vla-getremotefile)
    ;;;    (list objUTL
    ;;;   "http://www.uspconnectors.com/cad/product/hc520.dwg"
    ;;;   'locfile
    ;;;   :vlax-true
    ;;;    )
    ;;;  )
      (alert (strcat "File downloaded here -> " locfile))
      (princ)
    )
    I've included a commented section that does the same thing only wraps the function in VL-CATCH-ALL-APPLY which is for error trapping purposes. Just save the return from VL-CATCH-ALL-APPLY to a variable and check it with VL-CATCH-ALL-ERROR-P to see if the return threw an error and if so, use VL-CATCH-ALL-ERROR-MESSAGE to check the error.

    The document I referd you to earlier explains how to interpret the VBA documentation and translate that to Lisp. Essentially, most methods in VBA require an object. GETREMOTEFILE uses the UTILITY object and requires 3 arguments in VBA, in Lisp it requires 4, the first being the UTILITY object.

    The other thing that's different with ActiveX in Lisp from traditional Lisp is that you are use to a function returning a value to a variable. This happens in ActiveX based Lisp as well but there's times where you also need to specify a quoted empty variable (LOCFILE in this case) and the function 'back fills' (for lack of a beter term) the value into that variable. That's why you won't see a (SETQ LOCFILE ...) anywhere in the code yet LOCFILE does indeed store the value.

    The file is also downloaded using HTTP so it automatically get's stuffed into the temporary internet files folder where you can then move/copy it where ever you want.

    PS: The file used in the sample is valid and on the web (one of my former clients). If it doesn't download or work on your system, it's likley a filewall or permission issue with your systems.
    Last edited by Opie; 2009-05-18 at 06:49 PM. Reason: fixed [quote] tag

  2. #12
    Certifiable AUGI Addict
    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

    Technically what Darren's referring to is that the vla functions are a way of making LISP (a Procedural Oriented Programming Language) use Methods and Properties from ActiveX (as used in Visual Basic for Applications), which is an Object Oriented Programming Language (or tries to be). The LISP function is a "wrapper" to this method. The basic difference between func & meth is that a function takes inputs and passes a result, while a method can be a "function" or a "procedure" (which takes inputs, but also outputs, but returns no result), or a method could be a combination of the 2 returning a result but also changing the values of variables passed to it. A method is always part of an Object, a function or a procedure will be separate from anything else (this is the basic difference between Procedural- and Object Oriented).

    In VBA you'd have written:
    UtilityObject.GetRemoteFile ("http://www.uspconnectors.com/cad/product/hc520.dwg", locfile, True)
    Which basically says: "Call the UtilityObject's method named GetRemoteFile, passing it the 3 variables (a quoted string with url, a var for returning the file, and a True value to say ignore cached files & force download)."

    What happens in VLISP with this function (vla-GetRemoteFile UtilityObject "http://www.uspconnectors.com/cad/product/hc520.dwg" 'locfile Vlax:True) is "Perform function named GetRemoteFile on UtilityObject, passing the variables." The reason that locfile is prefixed with a single quote is to rather pass the "reference" to the variable so that the method places the filename into the original variable. If you didn't do this then a "new" variable is created inside the vla-GetRemoteFile function, it's value gets changed but not passed back. In VBA this is automatic since you tell the Method which variables are By Value and which are By Reference. Lisp doesn't have such a destinction - so you have to trick it every time you call the function.

    The easier type of vla function to understand is probably those wrapping the Object's Properties. These are the vla-get-... and vla-put-... functions. Although aff subject, I'm adding this for completeness. In VBA you'd have set an entity's Layer by:
    EnRef.Layer = "Layer1" the equivalent VLISP code is (vla-put-Layer EnRef "Layer1")
    And to get the entity's layer:
    VBA: Value = EnRef.Layer VLISP: (setq Value (vla-get-Layer EnRef))

  3. #13
    Login to Give a bone
    0

    Default Re: Visual Lisp Help - Check if URL Exists

    Nice explination Irneb.

    Another was to think of the 'locfile variable and understand why it's quoted, is to remember then everything in Lisp is evaluated to it's value. The function vla-getremotefile needs a variable to stuff a value into. Without quoting it, the variable is evaluated and locfile's value which would be NIL initially, would be passed to the vla-getremotefile function.

    Quoting thte varible names passes the variable name to the function and doesn't evaluate it to the value it holds.

    It was noted earlier in this thread that the VLA functions aren't documented. The reason for that is because they technically don't exist until a call to (vl-load-com) is made, then the functions are created for the AutoCAD object model. This isn't limited to just AutoCAD however. While this shortcut to creating Visp based commands for thr AutoCAD object model, you can do the same for any application that has an ActiveX object model like Excel or MS Word. Just use the (vlax-import-type-library) function to import the type library which will create a whole bunch of functions with the previx you define instead of vla-*, you could then have vlxls-* functions in Lisp that control Excel.

  4. #14
    Member
    Join Date
    2002-12
    Location
    Tolland CT
    Posts
    18
    Login to Give a bone
    0

    Default Re: Visual Lisp Help - Check if URL Exists

    Quote Originally Posted by DarrenYoung View Post
    Try this...

    Code:
      (setq objDOC (vla-get-activedocument (vlax-get-acad-object)))
      (setq objUTL (vla-get-utility objDOC))
    
      (vla-getremotefile
        objUTL
        "http://www.uspconnectors.com/cad/product/hc520.dwg"
        'locfile
        :vlax-true
      )
    Concise and just what I needed - thank you Darren!

Page 2 of 2 FirstFirst 12

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 AutoCAD General
    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
  •