getfiled to select a directory

getfiled to select a directory

john.uhden
Mentor Mentor
876 Views
14 Replies
Message 1 of 15

getfiled to select a directory

john.uhden
Mentor
Mentor

My ACAD2002 help says if I include flag 16 it will allow me to select a directory, but it doesn't work that way.

Might it work in newer releases so I can avoid having to use dos_getdir?

Don't get me wrong.  I love DOSLIB, but you seem to need a different version installed for almost every AutoCAD release.

John F. Uhden

0 Likes
Accepted solutions (1)
877 Views
14 Replies
Replies (14)
Message 2 of 15

Browning_Zed
Advocate
Advocate

This works for me:
(getfiled "Select Block" "" "dwg" 16))

0 Likes
Message 3 of 15

john.uhden
Mentor
Mentor

@Browning_Zed 

Yes, this is about BKEEPER,  but I don't think you're getting it.  Part of the issue is being able to select a directory (folder) not a file.

John F. Uhden

0 Likes
Message 4 of 15

Browning_Zed
Advocate
Advocate

*delete*

0 Likes
Message 5 of 15

phanaem
Collaborator
Collaborator

Alternatively to dos_getdir, you can use acet-ui-pickdir which come with ExpressTools

(acet-ui-pickdir [<message> [<start-dir> [<title>]]])

 

0 Likes
Message 6 of 15

pbejse
Mentor
Mentor

@john.uhden wrote:

My ACAD2002 help says if I include flag 16 it will allow me to select a directory, but it doesn't work that way.

Might it work in newer releases so I can avoid having to use dos_getdir?

Don't get me wrong.  I love DOSLIB, but you seem to need a different version installed for almost every AutoCAD release.


What about "Shell.Application" 

(setq sh (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application"))
(setq folder (vlax-invoke sh 'browseforfolder 0 "Browse" "&H10" ))
(vlax-release-object sh)
BIF_RETURNONLYFSDIRS = &H1        ' For finding a folder to start document searching
BIF_DONTGOBELOWDOMAIN = &H2       ' For starting the Find Computer
BIF_STATUSTEXT = &H4              ' Top of the dialog has 2 lines of text for BROWSEINFO.lpszTitle and one line if
	' this flag is set.  Passing the message BFFM_SETSTATUSTEXTA to the hwnd can set the
	' rest of the text.  This is not used with BIF_USENEWUI and BROWSEINFO.lpszTitle gets
	' all three lines of text.
BIF_RETURNFSANCESTORS = &H8
BIF_EDITBOX = &H10                ' Add an editbox to the dialog
BIF_VALIDATE = &H20               ' insist on valid result (or CANCEL)

BIF_NEWDIALOGSTYLE = &H40         ' Use the new dialog layout with the ability to resize
' Caller needs to call OleInitialize() before using this API

BIF_USENEWUI = (BIF_NEWDIALOGSTYLE Or BIF_EDITBOX)

BIF_BROWSEINCLUDEURLS = &H80      ' Allow URLs to be displayed or entered. (Requires BIF_USENEWUI)
BIF_UAHINT = &H100                ' Add a UA hint to the dialog, in place of the edit box. May not be combined with BIF_EDITBOX
BIF_NONEWFOLDERBUTTON = &H200     ' Do not add the "New Folder" button to the dialog.  Only applicable with BIF_NEWDIALOGSTYLE.
BIF_NOTRANSLATETARGETS = &H400    ' don't traverse target as shortcut
BIF_BROWSEFORCOMPUTER = &H1000    ' Browsing for Computers.
BIF_BROWSEFORPRINTER = &H2000     ' Browsing for Printers
BIF_BROWSEINCLUDEFILES = &H4000   ' Browsing for Everything
BIF_SHAREABLE = &H8000            ' sharable resources displayed (remote shares, requires BIF_USENEWUI)

HTH

Message 7 of 15

john.uhden
Mentor
Mentor

@pbejse 

That's cool, but all I get is a folder object without a name/path property.

Maybe this is a shortcoming of ACAD2002?

John F. Uhden

0 Likes
Message 8 of 15

hak_vz
Advisor
Advisor
Accepted solution

@john.uhden 

 

Here you can find a script from @Lee_Mac 's that uses "Shell application" to return selected directory.

Use this link for samples and detailed explanation

 

;; 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
    )
)

(LM:browseforfolder "Select folder" nil 0)

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 9 of 15

john.uhden
Mentor
Mentor

@hak_vz 

It's sort of an abbreviated looking dialog, but it works!

Thanks to you and @Lee_Mac.

I'll have to study why.

John F. Uhden

Message 10 of 15

john.kaulB9QW2
Advocate
Advocate

I always used the one from Tony T.

 

(defun BrowseForFolder ( str / sh folder folderobject result)
    ;; 
    ;; From: Tony Tanzillo 
    ;; Newsgroups: autodesk.autocad.customization
    ;;
    ;; (setq folder (BrowseForFolder "Select Folder"))
    ;;
    (vl-load-com)
    (setq sh
          (vla-getInterfaceObject
            (vlax-get-acad-object) "Shell.Application"))

    (setq folder (vlax-invoke-method sh 'BrowseForFolder 0 str 0))

    (vlax-release-object sh)

    (if folder
      (progn
        (setq folderobject (vlax-get-property folder 'Self))
        (setq result (vlax-get-property FolderObject 'Path))
        (vlax-release-object folder)
        (vlax-release-object FolderObject)
        result
        )
      )
    )

 

another swamper
0 Likes
Message 11 of 15

john.uhden
Mentor
Mentor

Thanks, John

That one has a little better flavor.  Tony T. is/was a very wise fellow.

John F. Uhden

0 Likes
Message 12 of 15

john.kaulB9QW2
Advocate
Advocate
Not a problem. If anyone finds his orig please post it (I don't think I did but I may have modified it slightly).
another swamper
0 Likes
Message 13 of 15

john.uhden
Mentor
Mentor

@john.kaulB9QW2 

Modified a Tony T. function?  That's blasphemy!

Although I am still wondering if it's necessary to release local objects.

Do you recall if Tony had done that?

John F. Uhden

0 Likes
Message 14 of 15

john.kaulB9QW2
Advocate
Advocate
I think I know what you are referring to (I seem to remember an explanation about when and when not to release objects) but I do not remember.
another swamper
0 Likes
Message 15 of 15

john.uhden
Mentor
Mentor

@john.kaulB9QW2 

Do you seem to remember this?

JohnK

  • Administrator
  • Seagull
  •  
  •  

     

  • Posts: 10069
  •  
 

 

(vlax-release-object obj) vs (setq obj nil)
« Reply #5 on: August 02, 2004, 04:48:33 PM »
 
*Sigh*  

Answer: Release at the end of your loop.

John F. Uhden

0 Likes