I was going to add these two functions to my website, but I have a couple of questions which have been on my mind for a little while.
Here are the functions:
;;----------------------=={ Open File }==---------------------;;
;; ;;
;; Uses the 'Open' method of the Shell Object to open the ;;
;; specified file. ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright © 2010 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; filename - filename of file to open ;;
;;------------------------------------------------------------;;
;; Returns: T if file opened successfully, else nil ;;
;;------------------------------------------------------------;;
(defun LM:OpenFile ( filename / Shell result ) (vl-load-com)
;; © Lee Mac 2010
(setq Shell (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application"))
(setq result
(and (setq filename (findfile filename))
(not
(vl-catch-all-error-p
(vl-catch-all-apply 'vlax-invoke (list Shell 'Open filename))
)
)
)
)
(vlax-release-object Shell)
result
)
;;-----------------------=={ Explore }==----------------------;;
;; ;;
;; Opens a specified folder in a Windows Explorer window. ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright © 2010 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; Directory - Directory or ShellSpecialFolderConstants ;;
;; Enumeration to open in Windows Explorer ;;
;;------------------------------------------------------------;;
;; Returns: T if directory opened in Explorer, else nil ;;
;;------------------------------------------------------------;;
(defun LM:Explore ( Directory / Shell result ) (vl-load-com)
;; © Lee Mac 2010
(setq Shell (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application"))
(setq result (vl-catch-all-apply 'vlax-invoke (list Shell 'Explore Directory)))
(vlax-release-object Shell)
(not (vl-catch-all-error-p result))
)
Upon testing, I notice that they operate correcty if either:
(vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application")
Or
(vlax-create-object "Shell.Application")
is used.
So, my question would be: Which is the correct method (if there is a preferred method), and what determines which to use?
Thank you for your time,
Lee