TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Shade on October 03, 2007, 11:50:56 AM

Title: Get Folder
Post by: Shade on October 03, 2007, 11:50:56 AM
Is there a way to get a folder path without selecting a file in the folder?

Sorta like getfiled but selecting a folder not a file.  :mrgreen:

Title: Re: Get Folder
Post by: T.Willey on October 03, 2007, 11:56:52 AM
Many variations of this have been posted, and this is Tony T.'s changed by me.
Code: [Select]
(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
        )
     )
  )
)
Title: Re: Get Folder
Post by: Guest on October 03, 2007, 11:58:47 AM
I've used this for a while now (got it from the now defunct AcadX.com site)

Code: [Select]
;;;==================================================================
;;; (JustPath cFileName)
;;; Returns the path portion of a complete path and file name.
;;;------------------------------------------------------------------
;;; Parameters:
;;; cFileName str to check
;;;------------------------------------------------------------------
;;; Returns:
;;; [STR]
;;; Example: (setq a "C:\\MyFolder\\MyFile.txt")
;;; (JustPath a) ; returns "C:\MyFolder"
;;;------------------------------------------------------------------
(defun JustPath (cFileName / bsLoc)
   (setq bsLoc (rat "\\" cfileName))
   (if   (> bsLoc 0)
      (substr cFilename 1 (1- bsLoc))
      ""
   ) ;_ end of if
) ;_ end of defun
Title: Re: Get Folder
Post by: deegeecees on October 03, 2007, 12:04:34 PM
Thanks Tim, I had needed this in the past, but never had time/success in creating/finding something similar. Looks like I'll be digging into some old projects. Fun, fun, fun...

 :lol:
Title: Re: Get Folder
Post by: T.Willey on October 03, 2007, 12:22:01 PM
Thanks Tim, I had needed this in the past, but never had time/success in creating/finding something similar. Looks like I'll be digging into some old projects. Fun, fun, fun...

 :lol:
Digging in old routines is MAJOR FUN!  :wink:  Glad I don't have to do it.  You're welcome ...... I guess.
Title: Re: Get Folder
Post by: CAB on October 03, 2007, 12:44:30 PM
Matt,
Code: [Select]
(vl-filename-directory "c:\\MyFolder\\MyFile.txt")
"C:\\MyFolder
Title: Re: Get Folder
Post by: T.Willey on October 03, 2007, 12:48:02 PM
Matt,

  You would also need to share the function 'Rat'.
Quote
Command: (JustPath Path)
; error: no function definition: RAT
Title: Re: Get Folder
Post by: Guest on October 03, 2007, 01:00:57 PM
Matt,
Code: [Select]
(vl-filename-directory "c:\\MyFolder\\MyFile.txt")
"C:\\MyFolder

Puh-tay-toe, Puh-tah-toe   :wink:

Thanks, CAB.
Title: Re: Get Folder
Post by: Guest on October 03, 2007, 01:02:00 PM
Matt,

  You would also need to share the function 'Rat'.
Quote
Command: (JustPath Path)
; error: no function definition: RAT

D'oh!

Code: [Select]
;;;===========================================================================
;;; (Rat cSearchExpression cExpressionSearched)
;;; Returns the numeric position of the last (rightmost)
;;; occurrence of a character string within another character string.
;;;---------------------------------------------------------------------------
;;; Parameters:
;;; cSearchExpression [STR] - String to search for
;;; cExpressionSearched [STR] - String to search
;;;---------------------------------------------------------------------------
;;; Returns:
;;; [INT] - Posistion of the string
;;; Example: (setq a "A Lot of Text.")
;;; (Rat "Text" a) ; returns 10
;;;===========================================================================
(defun Rat (cSearch cSearchIn / return SearchFor cont n)
;; We need to escape for special characters
(cond
(
(= cSearch "\\")
(setq SearchFor "*`\\*")
)
(
(= cSearch ".")
(setq SearchFor "*`.*")
)
(
(= cSearch "#")
(setq SearchFor "*`#*")
)
(
(= cSearch "*")
(setq SearchFor "*`**")
)
(
(= cSearch "~")
(setq SearchFor "*`~*")
)
(
(= cSearch "-")
(setq SearchFor "*`-*")
)
(
(= cSearch ",")
(setq SearchFor "*`,*")
)
(
(= cSearch "`")
(setq SearchFor "*``*")
)
(
T
(setq SearchFor (strcat "*" cSearch "*"))
)
) ;_ end of cond

(cond
(
;; Make sure there is a match
(not (wcmatch cSearchIn SearchFor))
(setq return 0)
)
(
T
(setq n (strlen cSearchIn))
(setq TestStr (substr cSearchIn n))
(setq cont T)
(while Cont
(if (wcmatch TestStr SearchFor)
(progn
(setq Cont nil)
(setq return n)
) ;_ end of progn
(progn
(setq n (1- n))
(setq TestStr (substr cSearchIn n))

) ;_ end of progn
) ;_ end of if
) ;_ end of while
)
) ;_ end of cond
return
) ;_ end of defun
Title: Re: Get Folder
Post by: FengK on October 03, 2007, 01:04:38 PM
fyi, if you're using doslib or don't mind using it, since version 7.0, it has a new function that displays an AutoCAD-style file selection dialog box. the syntax is:
(dos_getfilenav title default ext flags) when flags is set to 2048, it allows you to pick a folder.
Title: Re: Get Folder
Post by: ASMI on October 03, 2007, 01:19:01 PM
Or OpenDCL BrowseFolder function

Quote
--------------------------------------------------------------------------------

Method BrowseFolder as String
 
This method will prompt the user with a dialog box that allows the selection of directory folders only. 


AutoLISP Syntax:
(Setq rValue (dcl_BrowseFolder 
          Caption [as String]
          [Optiona]/DefaultDirectory [as String]
          [Optional]/RootFolder [as String]
          [Optional]/Flags [as String]))


<Flags> is a bit flag, and its default value is 1 (to return only file system folders). The following values used for <Flags> are from the Windows SDK header file in hexadecimal:
 
BIF_RETURNONLYFSDIRS 0x0001
BIF_DONTGOBELOWDOMAIN 0x0002
BIF_STATUSTEXT 0x0004
BIF_RETURNFSANCESTORS 0x0008
BIF_EDITBOX 0x0010
BIF_VALIDATE 0x0020
BIF_NEWDIALOGSTYLE 0x0040
BIF_USENEWUI (BIF_NEWDIALOGSTYLE | BIF_EDITBOX)
BIF_BROWSEINCLUDEURLS 0x0080
BIF_UAHINT 0x0100
BIF_NONEWFOLDERBUTTON 0x0200
BIF_NOTRANSLATETARGETS 0x0400
BIF_BROWSEFORCOMPUTER 0x1000
BIF_BROWSEFORPRINTER 0x2000
BIF_BROWSEINCLUDEFILES 0x4000
BIF_SHAREABLE 0x8000 (remote shares, requires BIF_USENEWUI)
 
See MSDN for information about each flag.
With the new combination of arguments, the flag argument will not be necessary for duplicating the original behavior and more, but it might still be fun to check out the new style UI (flag value decimal 81).

Edit: METHOD!
Title: Re: Get Folder
Post by: taybac21456 on August 13, 2023, 12:04:18 PM
https://forum.dwg.ru/showthread.php?t=81587

Can anyone help me or edit it. Lisp is perfect but can't export the layer to any file. I can't find the .txt .csv file in the selected export folder.
Title: Re: Get Folder
Post by: HasanCAD on August 14, 2023, 04:16:49 AM
https://forum.dwg.ru/showthread.php?t=81587

Can anyone help me or edit it. Lisp is perfect but can't export the layer to any file. I can't find the .txt .csv file in the selected export folder.

http://lee-mac.com/steal.html
Title: Re: Get Folder
Post by: JohnK on August 14, 2023, 10:51:08 AM
https://forum.dwg.ru/showthread.php?t=81587

Can anyone help me or edit it. Lisp is perfect but can't export the layer to any file. I can't find the .txt .csv file in the selected export folder.

I do not have a lot of time at the moment but to export the drawing layer settings you can do something as simple as:
Code - Auto/Visual Lisp: [Select]
  1. (defun save-layer-list-to-file ( / x f fp )
  2.   ;; retrieve all layers from dwg dict and save
  3.   ;; to a file.  file saved where drawing is located
  4.       (setq f (strcat (getvar 'DWGPREFIX) (getvar 'DWGNAME) ".la")
  5.             fp (open f "A"))
  6.       (while (setq x (tblnext "LAYER" (not x)))
  7.              (cond
  8.                ((not (>= (cdr (assoc 70 x)) 16))
  9.                 (prin1 x fp)
  10.                 (princ "\n" fp)) )
  11.              )
  12.       (close fp)
  13.       (princ) )

...
http://lee-mac.com/steal.html
After VERY QUICK look, that looks a lot like Design center (-i.e. what motivation is there for someone to use that tool vs design center or their current solution)? Meaning, the end-user is having problems editing current lisp, they may not be up for adding another solution instead of just editing their current tool--or adopting a built-in solution.