Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: Obtaining a directory path via a dialog

  1. #1
    I could stop if I wanted to
    Join Date
    2001-01
    Posts
    257
    Login to Give a bone
    0

    Talking Obtaining a directory path via a dialog

    Hi All-

    I am currently working on a lisp that requires that the user navigate to a directory where drawing files are store. What I need is help with a function that will display a dialog that will allow them to navigate to a directory and once they select the Ok button it will store the path to a variable. The rest of the program I already have working fine. Thanks in advance.

    Manuel A. Ayala

  2. #2
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Obtaining a directory path via a dialog

    Code:
    (defun Directory-Dia ( Message / sh folder folderobject result)
    ;; By Tony Tanzillo
    ;; Modified by Tim Willey
    ;; 16 Will let you type in the path
    ;; 64 Will let you create a new folder
    
    	(vl-load-com)
    	(setq sh
    		(vla-getInterfaceObject
    			(vlax-get-acad-object)
    			"Shell.Application"
    		)
    	)
    
    
    	(setq folder
    		(vlax-invoke-method
    			sh
    			'BrowseForFolder
    			(vla-get-HWND (vlax-get-Acad-Object))
    			Message
    			0 ; This is the bit number to change.
    		)
    	)
    	(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)
    			(if (/= (substr result (strlen result)) "\\")
    				(setq result (strcat result "\\"))
    				result
    			)
    		)
    	)
    )

  3. #3
    Login to Give a bone
    0

    Default Re: Obtaining a directory path via a dialog

    Tim,
    I like it, but is there anyway you can pass the default folder to your Directory-Dia function?
    Here's the method that I've been using so the AutoCAD users can also view the drawings in the folder they are selecting.
    This version uses the global variable *LastPath$ to remember the last folder selected.
    Terry

    Code:
    (defun GetPathName (/ PathFile$)
      (if (not *LastPath$)
        (setq *LastPath$ (getvar "DWGPREFIX"))
      );if
      (if (setq PathFile$ (getfiled "Select a Drawing in a folder for Folder name" *LastPath$ "dwg" 2))
        (setq *LastPath$ (strcat (vl-filename-directory PathFile$) "\\"))
      );if
    );defun GetPathName
    I removed (exit) from the function, but you might want to check it's value before continuing in your program. Something like this:
    Code:
    (if (not (setq Pathname$ (GetPathName)))
      (progn
        (alert "No Folder was selected.")
        (exit)
      );progn
    );if
    Last edited by Terry Cadd; 2008-05-08 at 01:53 AM. Reason: Removed (exit) from function.

  4. #4
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Obtaining a directory path via a dialog

    You could also try one of these free utilities:
    Both the above give a browse for folder dialog which includes a create folder button, unlike the standard Windows base dialog.

  5. #5
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Obtaining a directory path via a dialog

    Quote Originally Posted by Terry Cadd View Post
    Tim,
    I like it, but is there anyway you can pass the default folder to your Directory-Dia function?
    Not sure Terry. We I get a minute I'll look into it.

  6. #6
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Obtaining a directory path via a dialog

    Quote Originally Posted by T.Willey View Post
    Quote Originally Posted by TerryCad View Post
    Tim,
    I like it, but is there anyway you can pass the default folder to your Directory-Dia function?
    Not sure Terry. We I get a minute I'll look into it.
    I didn't see any way to give it a default location to start in.

  7. #7
    Login to Give a bone
    0

    Default Re: Obtaining a directory path via a dialog

    Tim,
    I liked your function so well, that I made my own version. This is some good stuff to know about. I experimented with the bit flag and found that negative numbers change even more of the dialog options, but you have to play around with the numbers. I ended up settling with bit flag 1. Also I found that you can add a start in folder, but the only draw back is that it can't navigate to other drives or higher up in the root structure than where the start in folder was. If you just use "" for the Directory$ argument you can navigate to other drives.
    Code:
    ;-------------------------------------------------------------------------------
    ; BrowseForFolder - Dialog to browse for a folder
    ; Arguments: 2
    ;   Message$ = Message line
    ;   Directory$ = Start in folder
    ; Syntax: (BrowseForFolder "\nTo view any subfolders, click a plus sign below." "C:\\")
    ; Returns: Name of folder selected
    ;-------------------------------------------------------------------------------
    (defun BrowseForFolder (Message$ Directory$ / FolderItem FolderObj FolderPath$ ShellApp)
      (setq ShellApp (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application"))
      (setq FolderObj (vlax-invoke-method ShellApp 'BrowseForFolder (vla-get-hwnd (vlax-get-acad-object)) Message$ 1 Directory$))
      (vlax-release-object ShellApp)
      (if FolderObj
        (progn
          (setq FolderItem (vlax-get-property FolderObj 'Self))
          (setq FolderPath$ (vlax-get-property FolderItem 'Path))
          (vlax-release-object FolderObj)
          (vlax-release-object FolderItem)
          (if (/= (substr FolderPath$ (strlen FolderPath$)) "\\")
            (setq FolderPath$ (strcat FolderPath$ "\\"))
          );if
          (if (/= (substr FolderPath$ 2 2) ":\\")
            (setq FolderPath$ nil)
          );if
        );progn
      );if
      FolderPath$
    );defun BrowseForFolder

  8. #8
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Obtaining a directory path via a dialog

    That's another thing about the utilities I've mentioned before. you place this into your LISP:
    Code:
    (setq path (dos_getdir "Browse  for folder" "C:\\Program Files\\AutoCAD 2002\\Sample\\" "Select a folder to use" T))
    Then it opens a dialog as per attached.
    Attached Images Attached Images

  9. #9
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Obtaining a directory path via a dialog

    Quote Originally Posted by irneb View Post
    That's another thing about the utilities I've mentioned before. you place this into your LISP:
    Code:
    (setq path (dos_getdir "Browse  for folder" "C:\\Program Files\\AutoCAD 2002\\Sample\\" "Select a folder to use" T))
    Then it opens a dialog as per attached.
    If you going to recommend this, then you should post the link to where they can grab it, as it's not a built in feature.

  10. #10
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Obtaining a directory path via a dialog

    Quote Originally Posted by T.Willey View Post
    If you going to recommend this, then you should post the link to where they can grab it, as it's not a built in feature.
    Check my previous post of yesterday - 2008-05-08. If you can't find it - here's the link again: http://www.en.na.mcneel.com/doslib.htm

Page 1 of 3 123 LastLast

Similar Threads

  1. Obtaining Uniform Thickness
    By seanmiller09593080 in forum AutoCAD General
    Replies: 3
    Last Post: 2011-11-09, 11:15 AM
  2. add a directory to Support File Search Path
    By NerdlingOne in forum AutoLISP
    Replies: 9
    Last Post: 2010-01-11, 08:52 PM
  3. Saving a drawing using dialog box to find path
    By d.kolinski in forum AutoCAD Customization
    Replies: 7
    Last Post: 2009-05-28, 06:56 PM
  4. import shp dialog doesn't show shp files in directory
    By gisdude in forum AutoCAD Map 3D - General
    Replies: 1
    Last Post: 2008-02-15, 01:08 AM
  5. Compare backslashes in directory path
    By daniel.111218 in forum AutoLISP
    Replies: 2
    Last Post: 2007-03-02, 07:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •