Open

Function Syntax (LM:open <target>)
Current Version 1.0
Donate
Arguments
Symbol Type Description
target String / Integer File, Folder or ShellSpecialFolderConstants Enum
Returns
Type Description
Boolean T if successful, else nil.

Function Description

This function is a wrapper for the Open method of the Shell Object to open either a file, folder or special folder (for example the Fonts folder) represented by a ShellSpecialFolderConstants enumeration - a reference for which may be found here.

The function will return T if the file or folder is opened successfully, else nil if either the file or folder is not found, or if the method returned an error during execution.

The ShellSpecialFolderConstants enumeration may be used to open special folders (such as Fonts, Program Files etc); such folders will be created if non-existent when used with this method. Note also that the hexadecimal value for the enumeration found in the aforementioned reference should be converted to decimal before being supplied to the function.

Select all
;; Open  -  Lee Mac
;; A wrapper for the 'Open' method of the Shell Object
;; target - [int/str] File, folder or ShellSpecialFolderConstants enum

(defun LM:open ( target / rtn shl )
    (if (and (or (= 'int (type target)) (setq target (findfile target)))
             (setq shl (vla-getinterfaceobject (vlax-get-acad-object) "shell.application"))
        )
        (progn
            (setq rtn (vl-catch-all-apply 'vlax-invoke (list shl 'open target)))
            (vlax-release-object shl)
            (if (vl-catch-all-error-p rtn)
                (prompt (vl-catch-all-error-message rtn))
                t
            )
        )
    )
)

Example Function Calls

Example to open a file selected by the user:

((lambda ( f ) (if f (LM:open f))) (getfiled "Select File" "" "" 16))

Example to open a drawing file from a specified location:

(LM:open "C:\\My Folder\\file.dwg")

Example to open a directory in Windows Explorer:

(LM:open "C:\\My Folder\\My Subfolder")

Example to open the Fonts Special Folder:

(LM:open 20)

textsize

increase · reset · decrease

Designed & Created by Lee Mac © 2010