Autolisp get the the full file name of the active lisp

Autolisp get the the full file name of the active lisp

Jedimaster
Collaborator Collaborator
1,027 Views
9 Replies
Message 1 of 10

Autolisp get the the full file name of the active lisp

Jedimaster
Collaborator
Collaborator

I am needing a way to get the full name of the active lisp. I am looking for a method to obtain the file name and path of the active lisp. I am aware of dos_lisplist, however not all users have doslib installed. I am able to get the current WScript with WScript.ScriptName. I am able to get the current vb.net  with My.Application.Info. I am trying to do this through lisp.

 

I am trying to do create a self stamp to determine the iteration/version of the active lsp or fas. I am using both vl-file-systime and vlax-create-object Scripting.FilesystemObject DateLastModified. I need the full name to get this information.

 

0 Likes
1,028 Views
9 Replies
Replies (9)
Message 2 of 10

Kent1Cooper
Consultant
Consultant

If you're talking about programming something to do this within the running of the active AutoLisp routine, then you know the name of the file you're writing it into, and as long as it's located in some folder in the Support File Search Path list in the Files tab in OPTIONS, you can get it returned to you along with the complete file path:

 

(findfile "YourFileName.lsp")

Kent Cooper, AIA
0 Likes
Message 3 of 10

Jedimaster
Collaborator
Collaborator

I appreciate the response, but the lisp file is located outside of the search path.

With vb.net  with My.Application.Info you get the current folder the launching application from. So if it moved it is self aware of where is located.  I do this with most of my .net applications to ensure the user does not lock out the network version. I copy the network application to  the local roamableroot folder as to not lock out the network .dll.

 

 

0 Likes
Message 4 of 10

pendean
Community Legend
Community Legend

@Jedimaster wrote:

...however not all users have doslib installed....


Why not just fix that issue at the core of your challenge instead?

0 Likes
Message 5 of 10

Kent1Cooper
Consultant
Consultant

@Jedimaster wrote:

.... the lisp file is located outside of the search path.

With vb.net  with My.Application.Info you get the current folder the launching application from. So if it moved it is self aware of where is located.  ....


That's all beyond my experience, but in terms of AutoLisp routines, I don't think there's any way for one of those, after being Loaded, to know or figure out from where it was loaded, or whether it even was loaded, or was [for example] written entirely within the current drawing with no external file at all, or was pasted in from copying code out of some source or other without use of APPLOAD or (load) or (autoload), or was dragged-&-dropped into the drawing without any of those Load options, or ....

Kent Cooper, AIA
Message 6 of 10

marko_ribar
Advisor
Advisor

I agree with Kent, but if you still are striving for active written *.lsp and it's active runtime validation, here is example you could use, but I warn you - it may be very time consuming and still if you have duplicate files at different places of HD - it'll stop at first one, which may be the one correct, but also the wrong one : firstly founded in process of searching...

 

(defun fullpath-running_lsp ( / _findfile _lstprmpt _drives filename fullpath ) ;;; main function - could be command function also, but active filename should match with it's name - i.e. for this example file should be saved as "fullpath-running_lsp.lsp" ;;;

  (defun _findfile ( libraryrootprefix filenamepatternlst subfoldersflag / subs processsubfolders folders r ) ;;; (_findfile "F:\\ACAD ADDONS-NEW" (list "profile*.lsp" "profile*.arg") t) ;;; searches for specific file and returns it's full path and filename with extension as soon as it finds first matching occurence ;;;

    (defun subs ( folder )
      (vl-remove "." (vl-remove ".." (vl-directory-files folder nil -1)))
    )

    (defun processsubfolders ( rootfolder / subfolders )
      (setq subfolders (subs rootfolder))
      (foreach sub subfolders
        (if (= (substr rootfolder (strlen rootfolder)) "\\")
          (setq r (cons (strcat rootfolder sub) (processsubfolders (strcat rootfolder sub))))
          (setq r (cons (strcat rootfolder "\\" sub) (processsubfolders (strcat rootfolder "\\" sub))))
        )
      )
      r
    )

    (setq folders (append (list libraryrootprefix) (if subfoldersflag (processsubfolders libraryrootprefix) folders)))
    (vl-some
      (function
        (lambda ( y )
          (if
            (and
              y
              (setq x
                (vl-some
                  (function
                    (lambda ( x )
                      (if (findfile (strcat y "\\" x))
                        x
                      )
                    )
                  )
                  (car
                    (vl-remove nil
                      (mapcar
                        (function (lambda ( filenamepattern )
                          (vl-directory-files y filenamepattern 1)
                        ))
                        filenamepatternlst
                      )
                    )
                  )
                )
              )
            )
            (strcat y "\\" x)
          )
        )
      ) folders
    )
  )

  (defun _lstprmpt ( / prmpt )
    (setq prmpt (getvar 'lastprompt))
    (setq prmpt (substr prmpt (+ 2 (vl-string-position (ascii " ") prmpt))))
    (cond
      ( (or
          (= "(c:" (substr prmpt 1 3))
          (= "(C:" (substr prmpt 1 3))
        )
        (setq prmpt (substr prmpt 4 (- (strlen prmpt) 4)))
      )
      ( (= "(" (substr prmpt 1 1))
        (setq prmpt (substr prmpt 2 (- (strlen prmpt) 2)))
      )
    )
    prmpt
  )

  (defun _drives ( / i d r )
    ;; Tharwat - Date: 24.Apr.2017 ;;
    (setq i 64)
    (while (< i 91)
      (if (vl-file-directory-p (setq d (strcat (chr (setq i (1+ i))) ":")))
        (setq r (cons d r))
      )
    )
    (vl-sort r (function <))
  )

  (setq filename (strcat (_lstprmpt) ".lsp"))
  (setq fullpath
    (vl-some
      (function (lambda ( drive / fn )
        (if (setq fn (_findfile drive (list filename) t))
          fn
        )
      ))
      (_drives)
    )
  )
  fullpath
)

 

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 7 of 10

Jedimaster
Collaborator
Collaborator

Well yes using I could get it to load doslib.arx from network. However, (dos_lisplist t) shows me all of the loaded lisp and fas. So grab the last one loaded. Well , what if I have subsequent lisp loaded, it is not the last one now. I could do a name search through out the list. I also have to know what the file name is. 

0 Likes
Message 8 of 10

Jedimaster
Collaborator
Collaborator

Thanks.  I would have to agree this would be too time consuming do a tree search on a drive that is 3TB and 2.69TB used. what I was hoping for is method in which it could look within itself  as .net has My.Application.Info.

right now I have

(setq Current_File_Name (findfile "ADMINISTRATION\\Somefolder\\MyApplication.fas"))

but I don't like having to hard code where the file is located.

The folder is not part of the search path as to keeping users from tampering with. 

 

0 Likes
Message 9 of 10

Sea-Haven
Mentor
Mentor

Have you looked at setting the support paths ? You could change it to reflect the path you want it to look for code in. So could do a look in C:\Cad-tools or in N:\Cad-tools only have 1 path set. We did this only looking for the server. The laptops though used on the road had 2 desktop icons, the icons had different profiles set look local or look on server. So got around the mobile problem office or car.

0 Likes
Message 10 of 10

Jedimaster
Collaborator
Collaborator

First of all, I appreciate everyone’s responds. I need to clarify what I am doing.

                 In Wscript there is a command WScript.ScriptFullName that returns the name and location of the current script. I use this for various reason one is to multi-thread search routines. The script knows to look in the same folder for subroutines and log files. This makes the script portable. I can place the script anywhere and run it.

                In VB.Net I use My.Application.Info.Title and My.Application.Info.DirectoryPath that returns the name and location of the current dll. This allows me to prevent a user from using the network version of dll. When you netload you lock out the dll. This prevents you from copying updates to the network.

                As far as the lisp, I have a routine that gets the modification date of a file. If the current lisp is copied elsewhere, it will not be looking at the correct file.

The best that I have come up with is dos_lisplist. It close but no cigar.

(setq LispApplciation "MyLisp")

(foreach ApplciationFullName (dos_lisplist t)
     (cond ((= (strcase (vl-filename-base ApplciationFullName)) (strcase LispApplciation))
          (princ ApplciationFullName)
    ))
)

I know how to find file, run through the search paths, tree a folder structure.

0 Likes