Get the path to the loaded lisp file

Get the path to the loaded lisp file

Browning_Zed
Advocate Advocate
5,191 Views
8 Replies
Message 1 of 9

Get the path to the loaded lisp file

Browning_Zed
Advocate
Advocate

When I load a lisp file using the drag-and-drop method, the command line shows the path to this file, something like: (LOAD "D: /MyDirectory/Test.LSP"). Now, can the path "D: / MyDirectory" be inserted into a variable as a string value? Thus, after loading the lisp file using the drag-and-drop method, must add a variable with the directory from which the file was loaded.

0 Likes
Accepted solutions (1)
5,192 Views
8 Replies
Replies (8)
Message 2 of 9

Kent1Cooper
Consultant
Consultant

I don't know of a way to do that, but if :

 

A)  such files are always coming from folder locations that are in the Support File Search Path list, and

B)  there would never be another file of the same name in any of those folder locations,

 

then you can find where the file is, whether or not it's been loaded:

 

(findfile "Test.lsp")

 

The result from that, which will include the file name too, can be put into a variable, and the file name lopped off the end if needed.  But that will return nil if it's not in one of those folder locations, also whether or not the file has been loaded.

Kent Cooper, AIA
0 Likes
Message 3 of 9

Browning_Zed
Advocate
Advocate

The problem is that the file must be loaded in order to create the Support file search path list and the Trusted locations list relative to the path of the loaded lisp file. That is, initially these lists do not exist.

0 Likes
Message 4 of 9

Anonymous
Not applicable

@Browning_Zed 

I don't know if this is your goal, you can use it >>Browse for Folder << the user will load the .lsp and he will ask for the folder where the program is.

 

 

0 Likes
Message 5 of 9

Browning_Zed
Advocate
Advocate

It looks like it might work. But how do I set a variable to assign the selected folder path to it?

0 Likes
Message 6 of 9

rkmcswain
Mentor
Mentor
@Browning_Zed wrote:

When I load a lisp file using the drag-and-drop method, the command line shows the path to this file, something like: (LOAD "D: /MyDirectory/Test.LSP"). Now, can the path "D: / MyDirectory" be inserted into a variable as a string value? 

My initial thought was no, but then I noticed that AutoCAD is storing that information somewhere, even if only in memory. If you run APPLOAD, it will show you the path from which a lisp file was loaded.

 

rkmcswain_0-1608296880316.png

 

Now how to access that info... ?

 

R.K. McSwain     | CADpanacea | on twitter
0 Likes
Message 7 of 9

Anonymous
Not applicable
Accepted solution

like this!  the path will be stored in the local variable.

(setq local (LM:browseforfolder "Select a folder" "C:\\Test" 0))

 

@Browning_Zed 

One point: do you want all the files in this folder to always be loaded in AutoCAD when starting?

0 Likes
Message 8 of 9

Browning_Zed
Advocate
Advocate

Thanks a lot. This works great.

Message 9 of 9

john.uhden
Mentor
Mentor

That's nice, but how can you find the path of a lisp file that's already been loaded?

Or even tougher... the path and name of a lisp file containing a c:Function that's already been loaded?

John F. Uhden