
Originally Posted by
Brenda Tanner
I would prefer to have the OPEN command pointing to a pre-defined path. This macro uses Windows Explorer, which is ok, but it doesn't bring up the typical File Open window in Autocad, instead it brings up an instance of Windows Explorer.
There are multiple ways to accomplish this, using GETFILED function for example, but just for fun:
Here's a sample Macro for a predefined location:
** Note - The use of a single forward-slash "/" in the macro, as double back-slash "\\" will result in a PAUSE for user input.
Code:
^C^C^P(_OpenHere "T:/Checker");._open;^P
... And the supporting "_OpenHere" LISP sub-function:
This sub-function accepts a single argument, a file path as String, and verifies that the file path is a valid location prior to updating the aptly named "InitialDirectory" registry key which defines the starting point for the OPEN dialog. This code also accounts for both pre, and post 2013 LISP functions for product key.
Code:
(vl-load-com)
(defun _OpenHere (filePath / key)
(if vlax-user-product-key ; If using 2013
(setq key (vlax-user-product-key)) ; Then, use new lisp function
(setq key (vlax-product-key)) ; Else, use legacy function
)
;; More info here:
;; http://www.cadtutor.net/forum/showthread.php?70845-AutoLISP-API-Changes-for-AutoCAD-2013-Updated
(if (setq
filePath (vl-string-translate
"\\"
"/"
(findfile (vl-string-right-trim
"/"
(vl-string-right-trim "\\" filePath)
)
)
)
)
(vl-registry-write
(strcat
"HKEY_CURRENT_USER\\"
key
"\\Profiles\\"
(vla-get-activeprofile
(vla-get-profiles
(vla-get-preferences (vlax-get-acad-object))
)
)
"\\Dialogs\\OpenSaveAnavDialogs"
)
"InitialDirectory"
filePath
)
)
(princ)
)
HTH
Bookmarks