Open help file pdf with revision

Open help file pdf with revision

eakos1
Advocate Advocate
753 Views
5 Replies
Message 1 of 6

Open help file pdf with revision

eakos1
Advocate
Advocate

I've made a small program to open a help file. But it can open only a file with an exact file name. 

Currently: AutoLISP_programs.pdf

 

But I want to store the files with revisions like: AutoLISP_programs_v000.pdf, AutoLISP_programs_v001.pdf ....

 

Is it somehow possible to read all the files what are in this folder, somehow read the names and check which is the highest version and open this file? 

 

 

(defun C:open_help (/)
  (vl-load-com)
  (vl-cmdf
    "start"
    "c:\\Acad_2015_Profile\\Programs\\Lisp\\HELP\\AutoLISP_programs.pdf"
  )
)					;defun

 

0 Likes
Accepted solutions (1)
754 Views
5 Replies
Replies (5)
Message 2 of 6

paullimapa
Mentor
Mentor
Accepted solution

Yes, you can use vl-directory-files to get a list of files matching certain pattern from a directory and sort this list so highest version # is first. Then open the first element in the list:

(defun C:open_help (/ fil)
  (vl-load-com)
  (if (setq fil (vl-directory-files "c:\\Acad_2015_Profile\\Programs\\Lisp\\HELP" "AutoLISP_programs*.pdf" 1))
     (vl-cmdf "start" (car (vl-sort fil '>)))
     (princ "\nNo AutoLISP_programs PDF files found.")
  )
 (princ)
) ; defun

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 6

scot-65
Advisor
Advisor

You can write into the LSP file the hard-path the directory containing the desired files.

I use a subdirectory "Documentation" to the user's menu system location or you can use the server location.

 

The trick is to read the contents in the directory and display as a list in a dialog box.

 

The user makes a selection of one item in the list...

 

scot65_0-1716580863134.png

 

To develop a program like this will be a good exercise for you.

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 4 of 6

paullimapa
Mentor
Mentor

@eakos1 to make life easier for you attached is a function called cd:DCL_StdListDialog I found which does exactly that. Just save the attached lisp file to a folder and make sure this folder is set under Options>Files> Support File Search Path & Trusted Locations

You feed a list as one of the arguments to this function and it'll display a dialog list box for selection.

With item selected it'll return the index number from the list.

Your modified code will look like this:

(defun C:open_help (/ fil idx)
  (vl-load-com)
  (if (setq fil (vl-directory-files "c:\\Acad_2015_Profile\\Programs\\Lisp\\HELP" "AutoLISP_programs*.pdf" 1))
     (progn
       (setq fil (vl-sort fil '>)) ; sorts latest to the top of the list
       (if(not cd:DCL_StdListDialog)(load "DCL_StdListDialog")) ; make sure this lisp is located in folder set under Options>Files> Support File Search Path & Trusted Locations
       (if (setq idx (cd:DCL_StdListDialog fil 0 "Title" "ListTitle:" 40 15 2 nil T nil)) ; display the dialog box to select from file list
         (vl-cmdf "start" (nth idx fil)) ; item selected
         (princ "\nNo AutoLISP_programs PDF file selected.") 
       )
     )
     (princ "\nNo AutoLISP_programs PDF files found.")
  )
 (princ)
) ; defun

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 5 of 6

CodeDing
Mentor
Mentor

@paullimapa ,

Well now I feel silly, because i was actually trying to sort the numbers at the end of the file hahahah

Posting anyways:

 

(defun c:OPEN_HELP ( / folder)
  (setq folder "C:\\users\\me\\desktop")
  (startapp "explorer"
    (strcat folder "\\"
      (cdar
        (vl-sort
          (mapcar
            '(lambda (file / numStr chars)
              (setq numStr nil chars (cddddr (reverse (vl-string->list file))))
              (while (<= 48 (car chars) 57)
                (setq numStr (cons (car chars) numStr) chars (cdr chars))
              );while
              (cons (vl-list->string numStr) file)
            );lambda
            (vl-directory-files folder "*.pdf" 1)
          );mapcar
          '(lambda (x y) (> (car x) (car y)))
        );vl-sort
      );cdar
    );strcat
  );startapp
  (princ)
);defun

 

Best,

~DD

0 Likes
Message 6 of 6

paullimapa
Mentor
Mentor

well, I like how you use the startapp function & explorer to get it done so here's my modified version:

(defun C:open_help (/ fil folder)
  (vl-load-com)
  (setq folder "c:\\Acad_2015_Profile\\Programs\\Lisp\\HELP")
  (if (setq fil (vl-directory-files folder "AutoLISP_programs*.pdf" 1))
     (startapp "explorer" (strcat folder "\\" (car (vl-sort fil '>))))
     (princ "\nNo AutoLISP_programs PDF files found.")
  )
 (princ)
) ; defun

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos