Include file name in tool

I got a toolbar button. Command is just like MYLISP
The LISP opens a file dialog (also if I set filedia=0) for pointing to a text file.
Now I want to add path and filename in my command so the text file is selected by auto.
How to?

(NO I do not want to edit the LISP)

Comments

  • ALANH
    edited June 2023
    You will have to edit the lisp that gets filename. I have something like this (setq filename "")(load "lisp") other button is (setq fileame "c:\abcdefg")(load "lisp") in Lisp is a IF looking at file name if blank then ask else skip.
  • Mikael63 said:


    (NO I do not want to edit the LISP)

    Hm.. okay..
    I got this first in the lisp:
    (defun FileToList (Filename / File Str FileLst)
    (if (and (findfile Filename) (setq File (open Filename "r")))
    ;then
    (progn
    (while (setq Str (read-line File))
    (if (/= Str "")
    (setq FileLst (cons (Split Str "\t") FileLst)) ;***
    )
    )
    (close File)
    (reverse FileLst)
    )
    )
    )


    How to change?
    It is not my own file, just a file I found...


  • Looks like your file is tab separated so look at this to make a list of each line then use cons.

    ; thanks to Lee-mac for this defun
    (defun csv->lst ( str / pos )
    (if (setq pos (vl-string-position 9 str))
    (cons (substr str 1 pos) (csv->lst (substr str (+ pos 2))))
    (list str)
    )
    )

    (setq str "172.473 E 427.898 4.969")
    (setq lst (csv->lst str))

    ("172.473" "E" "427.898" "4.969")

    32 is space, 9 is tab, 44 is comma.
  • Eh?
    My file works just fine as well as the LISP.
    I only want an easier way than to point to the file, by a file dialog.
  • Save the file always in one directory and one name, then hard code.