TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Marc'Antonio Alessi on February 04, 2023, 05:04:57 AM

Title: BrowseForFolder vs. dos_getdir
Post by: Marc'Antonio Alessi on February 04, 2023, 05:04:57 AM

I'm looking for a function similar to dos_getdir that allows me to set a default path and the possibility of going to a higher level.
All those I have found (the best one is that of LeeMac that I report) do not allow to go to a higher level than the default path.
Code: [Select]

;; Browse for Folder  -  Lee Mac
;; Displays a dialog prompting the user to select a folder.
;; msg - [str] message to display at top of dialog
;; dir - [str] [optional] root directory (or nil)
;; bit - [int] bit-coded flag specifying dialog display settings
;; Returns: [str] Selected folder filepath, else nil.
 
(defun LM:browseforfolder ( msg dir bit / err fld pth shl slf )
    (setq err
        (vl-catch-all-apply
            (function
                (lambda ( / app hwd )
                    (if (setq app (vlax-get-acad-object)
                              shl (vla-getinterfaceobject app "shell.application")
                              hwd (vl-catch-all-apply 'vla-get-hwnd (list app))
                              fld (vlax-invoke-method shl 'browseforfolder (if (vl-catch-all-error-p hwd) 0 hwd) msg bit dir)
                        )
                        (setq slf (vlax-get-property fld 'self)
                              pth (vlax-get-property slf 'path)
                              pth (vl-string-right-trim "\\" (vl-string-translate "/" "\\" pth))
                        )
                    )
                )
            )
        )
    )
    (if slf (vlax-release-object slf))
    (if fld (vlax-release-object fld))
    (if shl (vlax-release-object shl))
    (if (vl-catch-all-error-p err)
        (prompt (vl-catch-all-error-message err))
        pth
    )
)
Title: Re: BrowseForFolder vs. dos_getdir
Post by: Lee Mac on February 04, 2023, 07:13:16 AM
I'm not aware of a way to achieve this using the LISP API; I'd happily be proved wrong!
Title: Re: BrowseForFolder vs. dos_getdir
Post by: It's Alive! on February 04, 2023, 08:00:20 AM
trying to get rid of doslib?
Title: Re: BrowseForFolder vs. dos_getdir
Post by: Stefan on February 04, 2023, 08:22:12 AM
I'm looking for a function similar to dos_getdir that allows me to set a default path and the possibility of going to a higher level.

Alternatively, you can use (acet-ui-pickdir "Select folder" "C:\\"). I'm not sure, but I think it belongs to ExpressTools extension, which is installed by default.
Title: Re: BrowseForFolder vs. dos_getdir
Post by: Marc'Antonio Alessi on February 04, 2023, 09:15:19 AM

trying to get rid of doslib?
yes, It's something I've been trying to do for years...
I am using these functions:

Dos_Computer (Getenv "Computername")
Dos_Hostname (Getenv "Userdomain")
Dos_Username (Getenv "Username")

Dos_Checklist
Dos_Copy
Dos_Delete
Dos_Exewait
Dos_File
Dos_Filedate
Dos_Find
Dos_Getfilem
Dos_Getini
Dos_Getint
Dos_Getpassword
Dos_Getprn
Dos_Getprogress
Dos_Ispoweruser
Dos_Iswin64
Dos_Listbox
Dos_Move
Dos_Msgbox
Dos_Msgboxex
Dos_Multilist
Dos_Openp
Dos_Pathbackslash
Dos_Printers
Dos_Proplist
Dos_Pwdir
Dos_Setini
Dos_Setprn
Dos_Shellexe
Dos_Splitpath
Dos_Spool
Dos_Ver
Dos_Waitcursor

Title: Re: BrowseForFolder vs. dos_getdir
Post by: Marc'Antonio Alessi on February 04, 2023, 09:17:49 AM
I'm looking for a function similar to dos_getdir that allows me to set a default path and the possibility of going to a higher level.

Alternatively, you can use (acet-ui-pickdir "Select folder" "C:\\"). I'm not sure, but I think it belongs to ExpressTools extension, which is installed by default.
yes I know but I prefer to use DoLib instead of ExpressTools...  8)
Title: Re: BrowseForFolder vs. dos_getdir
Post by: BIGAL on February 04, 2023, 05:35:50 PM
Once you get the directory you can pull it apart and look at level above, I think the lisp I am looking for is splitstr it is a lisp function odd name, I have used it.

"C:\\dir1\\dir2\\dir3\\dir4"

so = ("dir1" "dir2" dir3" dir4") so answer required is  c:\\dir1\\dir2\\dir3 ie strcat (up to length-1)
Title: Re: BrowseForFolder vs. dos_getdir
Post by: It's Alive! on February 04, 2023, 08:36:59 PM

trying to get rid of doslib?
yes, It's something I've been trying to do for years...
...

There was a time I felt the same, but now that it’s open source, I wouldn’t mind the dependency.
Title: Re: BrowseForFolder vs. dos_getdir
Post by: Marc'Antonio Alessi on February 05, 2023, 03:22:24 AM
Once you get the directory you can pull it apart and look at level above, I think the lisp I am looking for is splitstr it is a lisp function odd name, I have used it.

"C:\\dir1\\dir2\\dir3\\dir4"

so = ("dir1" "dir2" dir3" dir4") so answer required is  c:\\dir1\\dir2\\dir3 ie strcat (up to length-1)
Code: [Select]
; (ALE_Files_SplitDirs "c:/123/456/789")    > ("c:" "123" "456" "789")
; (ALE_Files_SplitDirs "c:\\123\\456\\789") > ("c:" "123" "456" "789")
; (ALE_Files_SplitDirs "\\\\123\\456\\789") > ("123" "456" "789")
;
; original by Michael Puckett
;
(defun ALE_Files_SplitDirs (PatStr / OutLst TmpStr StrLng TmpCar)
  (setq TmpStr ""  StrLng (1+ (strlen PatStr)))
  (repeat (strlen PatStr)
    (if (member (setq TmpCar (substr PatStr (setq StrLng (1- StrLng)) 1)) '( "\\" "/"))
      (if (/= TmpStr "") (setq OutLst (cons TmpStr OutLst) TmpStr ""))
      (setq TmpStr (strcat TmpCar TmpStr))
    )
  )
  (if (/= TmpStr "") (cons TmpStr OutLst) OutLst)
)
but what I'm looking for is the ability to switch for example from one path in one drive to another in a different drive