I'm trying to create a script that requires the user to select the starting folder for their project. I have found several sources, but the coding languages are not what I'm using. The language I'm using is Autolisp which will most likely be calling for the shell application to open the desired GUI.
In addition, there is the code created by Lee Mac which comes close, but it uses a dialog box that restricts the user from accessing parent directories if a starting directory is given: Browse for Folder
Is there a way to open the "Select Folder" GUI as shown below, preferably by using AutoLisp?
The only other method with which I'm familiar (aside from utilising the BrowseForFolder method of the Windows Shell object - per this example) and which is exposed to ActiveX is to leverage the MS Office File Dialog object, e.g.:
;; File Dialog - Lee Mac
;; Leverages the MS Office File Dialog object to present a dialog to the user
;; msg - [str] Dialog title ("" for default)
;; btn - [str] Button name ("" for default)
;; ini - [str] Initial filename/directory
;; typ - [int] MsoFileDialogType (1-4)
;; mtp - [bol] Allow multiple selection (:vlax-true/:vlax-false)
(defun LM:filedialog ( msg btn ini typ mtp / dlg rtn xla )
(if (setq xla (vlax-create-object "excel.application"))
(progn
(setq rtn
(vl-catch-all-apply
(function
(lambda ( / tmp )
(setq dlg (vlax-get-property xla 'filedialog typ))
(vlax-put-property dlg 'title msg)
(vlax-put-property dlg 'buttonname btn)
(vlax-put-property dlg 'initialfilename ini)
(vlax-put-property dlg 'allowmultiselect mtp)
(vlax-put-property xla 'visible :vlax-true)
(if (= -1 (vlax-invoke-method dlg 'show))
(vlax-for itm (vlax-get-property dlg 'selecteditems)
(setq tmp (cons itm tmp))
)
)
)
)
)
)
(if dlg (vlax-release-object dlg))
(if xla (vlax-release-object xla))
(if (vl-catch-all-error-p rtn)
(prompt (vl-catch-all-error-message rtn))
rtn
)
)
)
)
Example
(LM:filedialog "Select a Folder" "Select Folder" "" 4 :vlax-false)
However, since the dialog is invoked using a method derived from an MS Office Application object, this requires instantiating said application object and is therefore obviously not quite as clean an outcome.