+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 16
  1. #1
    Senior Member lfe011969's Avatar
    Using
    AutoCAD 2009
    Join Date
    Apr 2010
    Location
    Newport News, VA
    Posts
    157

    Default Using vl-directory-files to populate list box

    Registered forum members do not see this ad.

    I'm trying to learn the vl path to lisp programming and I've run into a little snag using the 'vl-directory-files' command to populate a list box. The sample program I'm working on works fine and the contents of the folder specified in my lisp file is indeed displayed in the list box however there are two additional entries in the list, "." and ".." which I'm assuming has something to do with using vl (see pic below).

    notes.JPG

    Here's the code from my lisp:
    Code:
    (defun c:notes ()
      (setq folderList (vl-directory-files "L:\\Scripts\\Notes\\" nil -1))
      (setq dcl_id (load_dialog "notes1.dcl"))
      (if (not (new_dialog "NOTES1" dcl_id))(exit))
      (start_list "folderlist" 3)
      (mapcar 'add_list folderList)
      (end_list)
      (action_tile "cancel" "(setq ddiag 1)(done_dialog)")
      (action_tile "accept" "(setq ddiag 2)(done_dialog)")
      (start_dialog)
      (if (= ddiag 1)
        (princ "\n \n ...Notes Cancelled. \n ")
        )
      (if (= ddiag 2)
        (foreach a retList
          (princ "\n")(princ a)
          )
        )
      (princ)
      )

    Does anyone know of a way to remove the "." and the ".." so they don't show in the list? The only options for vl-directory-files that I know of are 1 (show files only), 0 (show both folders and files) and -1 (show folders only).

    Lonnie

  2. #2
    Super Moderator rkmcswain's Avatar
    Computer Details
    rkmcswain's Computer Details
    Operating System:
    Windows 7 Pro x64
    Computer:
    HP ZBook 17
    CPU:
    i7-4810MQ @ 2.80 GHZ
    RAM:
    16GB
    Graphics:
    Nvidia Quadro K4100M
    Primary Storage:
    256GB SSD
    Secondary Storage:
    1TB SATA
    Monitor:
    (2) HP 23"
    Discipline
    Civil
    rkmcswain's Discipline Details
    Discipline
    Civil
    Details
    CAD Manager
    Using
    Civil 3D 2017
    Join Date
    Sep 2005
    Location
    Houston
    Posts
    4,466

    Default

    The "." is the current directory, and the ".." is one directory up, or the parent directory.
    Just remove them from the list if not needed.

    Code:
    (vl-remove-if
      '(lambda (x) (or (eq x ".") (eq x "..")))
      (vl-directory-files "C:\\temp" nil -1)
    )
    R.K. McSwain
    CAD Panacea | twitter

  3. #3
    Senior Member lfe011969's Avatar
    Using
    AutoCAD 2009
    Join Date
    Apr 2010
    Location
    Newport News, VA
    Posts
    157

    Default

    Thanks that worked great! I was actually playing around with the vl-remove command just now but couldn't get it to work. And I glanced over the directions for vl-remove-if and vl-remove-if-not but not being experienced with any of these commands I thought I'd give the base command a try first.

    Lonnie

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,418

    Default

    Hi Lonnie,

    Perhaps this will help you also - note how I have structured the function, and the lack of action_tile statements, using the start_dialog return.

    Code:
    (defun c:notes ( / folders dcl_id sel flag )
    
      (cond ( (not (setq folders (vl-remove "." (vl-remove ".." (vl-directory-files "L:\\Scripts\\Notes\\" nil -1))))))
    
            ( (<= (setq dcl_id (load_dialog "notes1.dcl")) 0)
    
              (princ "\n** Unable to Locate DCL **")
            )
            ( (not (new_dialog "NOTES1" dcl_id))
    
              (princ "\n** Unable to Load Dialog **")
            )
            (t
              (start_list "folderlist")
              (mapcar 'add_list folders)
              (end_list)
    
              (setq sel (set_tile "folderlist" "0"))
             
              (action_tile "folderlist" "(setq sel $value)")
    
              (setq flag (start_dialog) dcl_id (unload_dialog dcl_id))
    
              (if (= 1 flag)
                (princ (strcat "\nUser Selected: " (nth (atoi sel) folders)))
                (princ "\nCancelled")
              )
            )
      )
    
      (princ)
    )
    Any questions, just ask. (untested code btw).
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  5. #5
    Senior Member lfe011969's Avatar
    Using
    AutoCAD 2009
    Join Date
    Apr 2010
    Location
    Newport News, VA
    Posts
    157

    Default

    What does the $value represent? I won't be home for a while so I can't look this up myself (using my droid for this) and my curiosity is getting the best of me.

  6. #6
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,418

    Default

    It is the current value of the tile, eg. string from an edit box, or "1" or "0" from a toggle etc etc

    See here:

    Code:
    Working with  Programmable Dialog Boxes > Managing Dialog  Boxes > Action  Expressions and Callbacks > Action Expressions
    In ACAD Dev Help
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  7. #7
    Senior Member lfe011969's Avatar
    Using
    AutoCAD 2009
    Join Date
    Apr 2010
    Location
    Newport News, VA
    Posts
    157

    Default

    So I've been studying the code and I think I get what you're doing but coding-wise, I'm still crawling while you're trying to make me run a marathon, lol.

    My intention was to start with a one-list list box routine then go to a two-list list box routine followed by a 3-list list box program. I've got some code for the 2-list program but the contents of the 2nd list box do not change based on what's selected in the first list box which is what I'm looking to do.
    Code:
    (defun saveVars    ()
      (setq fStr (get_tile "folderlist"))
      (if (/= fStr "")
        (progn
          (setq fIndex (atoi fStr))
          (setq fName (nth fIndex folderList))
          )
        
        (progn
          (setq fIndex -1)
          (setq fName nil)
        )
      )
    
      (setq nStr (get_tile "noteslist"))
      (if (/= nStr "")
        (progn
          (setq nIndex (atoi nStr))
          (setq nName (nth nIndex notesList))
          )
        (progn
          (setq nIndex -1)
          (setq nName nil)
          )
        )
      )
    
    (defun c:notes ()
      (setq    folderList
         (vl-remove-if
           '(lambda (x) (or (eq x ".") (eq x "..")))
           (vl-directory-files "L:\\Scripts\\Notes\\" nil -1)
         )
      )
    
      (cond
        (= fName "Electrical")(setq folderpath "L:\\Scripts\\Notes\\Electrical\\")
        (= fName "General")(setq folderpath "L:\\Scripts\\Notes\\General\\")
        (= fName "Outfitting")(setq folderpath "L:\\Scripts\\Notes\\Outfitting\\")
        (= fName "Piping")(setq folderpath "L:\\Scripts\\Notes\\Piping\\")
        (= fName "Removal")(setq folderpath "L:\\Scripts\\Notes\\Removal\\")
        (= fName "Structure")(setq folderpath "L:\\Scripts\\Notes\\Structure\\")
        (= fName "Test")(setq folderpath "L:\\Scripts\\Notes\\Test\\")
        )
    
      (setq notesList
         (vl-directory-files folderpath nil 1)
        )
    
      (setq dcl_id (load_dialog "notes1.dcl"))
      (if (not (new_dialog "NOTES1" dcl_id))
        (exit)
      )
    
      (start_list "folderlist" 3)
      (mapcar 'add_list folderList)
      (end_list)
    
      (start_list "notelist" 3)
      (mapcar 'add_list noteList)
      (end_list)
    
      (action_tile "cancel" "(setq ddiag 1)(done_dialog)")
      (action_tile "accept" "(setq ddiag 2)(saveVars)(done_dialog)")
      (action_tile "folderlist" "(saveVars)")
      
      (start_dialog)
      (if (= ddiag 1)
        (princ "\n \n ...Notes Cancelled. \n ")
      )
      (if (= ddiag 2)
        (foreach a retList
          (princ "\n")
          (princ a)
        )
      )
      (princ)
    )

    I took the principles of a one list list box and tried to apply them to a two list one but the second list box never gets populated and the error "; error: bad argument type: stringp nil" is returned by AutoCAD as soon as any of the items in the first list box is selected.

    How do you go about linking the two lists together so that selecting something in the 1st list changes the list in the 2nd one? Thanks.

    Lonnie

  8. #8
    Quantum Mechanic
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    10,025

    Default

    Just a guess it may be a problem of saying display 2nd list box but its got nothing to display so just put a blank entry into it "Pick box 1 first " when you first open the dcl then have a if pick box 1 change box2 and so on for box 3 4

  9. #9
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,418

    Default

    Hi Lonnie, I have an example posted here somewhere that does EXACTLY what you are looking for, I shall find it for you
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  10. #10
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,418

    Default

    Registered forum members do not see this ad.

    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

Similar Threads

  1. populate array
    By Lt Dan's legs in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 12th May 2010, 05:38 pm
  2. How to copy a list of files from one directory to another?
    By MarcoW in forum AutoLISP, Visual LISP & DCL
    Replies: 13
    Last Post: 7th Mar 2010, 03:37 pm
  3. LIST to TXT files
    By Coosbaylumber in forum AutoCAD General
    Replies: 5
    Last Post: 11th Nov 2009, 10:48 pm
  4. Trouble setting up drawing files directory in My Documents
    By berol in forum AutoCAD Beginners' Area
    Replies: 4
    Last Post: 7th May 2009, 04:29 am
  5. Opening Files from same directory?
    By Ste1978 in forum AutoCAD Drawing Management & Output
    Replies: 1
    Last Post: 31st May 2006, 12:51 pm

Bookmarks

Posting Permissions

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