Ahankhah Posted April 26, 2011 Author Posted April 26, 2011 I'm still completely perplexed why you are pursuing this, given that you already know that the sub-function ("reference program") resides within the same directory. RenderMan, please do these steps to see what I mean: 1- Make a file named "main.lsp" with this code:(alert"I am here inside main.lsp")(load"ref.lsp") 2- Make another file named "ref.lsp" with the following code: (alert"Now I am in ref.lsp") 3- move both of then in "c:\\test\\" folder. 3- Make sure that "c:\\test" folder isn't in search path of autocad. 4- Enter AutoCAD 5- APPLOAD "main.lsp" 6- You see that, although YOU KNOW where the second lisp file is, autocad DOESN'T. This is the problem. Quote
Ahankhah Posted April 26, 2011 Author Posted April 26, 2011 When a file is loaded into memory, you only have access to the defined symbols in the document namespace, not the file from which they were loaded. Sadly, I agree with you Lee. Quote
BlackBox Posted April 26, 2011 Posted April 26, 2011 RenderMan,please do these steps to see what I mean: This is the problem. AutoCAD cannot find ref.lsp, because you neglected to include the file path in the load statement. In order for your load statement to work (as is), the file path must be included in the Support Files Search Paths (SFSP). APPLOAD is simply providing the file path for main.lsp, and not for any other files. For example: If you remove main.lsp from APPLOAD (you may need to restart AutoCAD), then (findfile "main.lsp") = nil ... this is no different for ref.lsp, my friend. This is the very reason we have suggested that you simply include the file path in your SFSP, so that simpler, more succinct load statements are successful. I hope this helps! Quote
JohnM Posted April 26, 2011 Posted April 26, 2011 Here is a good starting point that will get you what you want. I don’t have time to write it but it will be a good exercise for you. HKEY_CURRENT_USER\software\Microsoft\windows\current version\explorer\comdlg32\opensavemRU\* When you appload a lisp or vlx file it will be listed in the above registry key You can use the vl-registry-read function to retrieve the paths then use findfile to locate the file you want. You will have to trim out the file name and extension of the returned path and insert the file and extension that you want. Just loop through the returned paths until you locate the file. Quote
Ahankhah Posted April 27, 2011 Author Posted April 27, 2011 Renderman, the path of ref.lsp isn't known to programmer, unless he/she goes every where with his/her program and every time modifies the path in the code. The only obvious thing is they are in the same directory. Getting the path of main.lsp is the only way to know where is ref.lsp. (as mentioned both are in the same path.) The thing I am searching is where APPLOAD command saves the path of loaded program. It is the clue. Quote
Ahankhah Posted April 27, 2011 Author Posted April 27, 2011 Here is a good starting point that will get you what you want.I don’t have time to write it but it will be a good exercise for you. HKEY_CURRENT_USER\software\Microsoft\windows\current version\explorer\comdlg32\opensavemRU\* When you appload a lisp or vlx file it will be listed in the above registry key You can use the vl-registry-read function to retrieve the paths then use findfile to locate the file you want. You will have to trim out the file name and extension of the returned path and insert the file and extension that you want. Just loop through the returned paths until you locate the file. Many thanks to you, JohnM, you mentioned to the clue. Thanks all guys for spending their time here. Quote
LibertyOne Posted April 27, 2011 Posted April 27, 2011 After a bit of research I came across the AutoLisp function (arx) which returns a list of loaded ARX aps. If you combine this with: (mapcar 'findfile (arx)) it will return a list with the filepath of the ARX apps that are loaded. Too bad there isn't something like that for LSP files. Well, actally there is in DOSLIB, but that's an external arx-file and not a function in AutoLisp. Quote
MSasu Posted April 27, 2011 Posted April 27, 2011 After a bit of research I came across the AutoLisp function (arx) which returns a list of loaded ARX aps. If you combine this with: (mapcar 'findfile (arx)) it will return a list with the filepath of the ARX apps that are loaded. I'm affraid that this is true only for ARX files that are in AutoCAD's defined search paths; for other will return nil. Regards, Mircea Quote
BlackBox Posted April 27, 2011 Posted April 27, 2011 ... The thing I am searching is where APPLOAD command saves the path of loaded program. It is the clue. Many thanks to you, JohnM,you mentioned to the clue. Thanks all guys for spending their time here. Ahankhah, I'm glad you were able to find a solution. Cheers! Quote
pBe Posted April 27, 2011 Posted April 27, 2011 I'm affraid that this is true only for ARX files that are in AutoCAD's defined search paths; for other will return nil. Regards, Mircea HA! hence my first post Quote
Ahankhah Posted April 27, 2011 Author Posted April 27, 2011 Hello all, as a result of this good discussion, finally I have written right codes. If the lisp/fas/vlx program is loaded by APPLOAD command, the desired folder can be found this way: (defun MT-Get-Last-Appload-Folder (/ acad CurVer1 CurVer2 CurProf RegPath folder) (setq acad "HKEY_CURRENT_USER\\software\\Autodesk\\AutoCAD\\") (setq CurVer1 (strcat (vl-registry-read acad "CurVer") "\\")) (setq CurVer2 (vl-registry-read (strcat acad "\\" CurVer1) "CurVer")) (setq acad (strcat acad CurVer1 CurVer2)) (setq CurProf (vl-registry-read (strcat acad "\\Profiles") "")) (setq RegPath (strcat acad "\\Profiles\\" CurProf "\\Dialogs\\Appload")) (setq folder (vl-registry-read RegPath "MainDialog")) ) (alert (MT-Get-Last-Appload-Folder)) But perhaps the program is loaded directly by issuing (load "program-name"), so in this condition the method mentioned by JohnM works: (defun MT-Get-Loaded-Files (ext / data-count val-names-list val-data files) (if (null ext) (setq ext "*") ) (setq data-count (vl-registry-read (strcat "HKEY_CURRENT_USER\\software\\Microsoft\\windows\\currentversion\\explorer\\comdlg32\\opensavemRU\\" ext ) "MRULIST" ) ) (setq val-names-list (vl-string->list data-count)) (foreach n val-names-list (if (setq val-data (vl-registry-read (strcat "HKEY_CURRENT_USER\\software\\Microsoft\\windows\\currentversion\\explorer\\comdlg32\\opensavemRU\\" ext ) (chr n) ) ) (setq files (cons val-data files)) ) ) files ) (MT-Get-Loaded-Files "*")(MT-Get-Loaded-Files "lsp") (MT-Get-Loaded-Files "fas") (MT-Get-Loaded-Files "arx") (MT-Get-Loaded-Files "vlx") (MT-Get-Loaded-Files "doc") ... 1 Quote
irneb Posted May 16, 2011 Posted May 16, 2011 While that works fine for manually loaded LSPs through the AppLoad command, what about those in the Startup Suite, or inside the ACad.LSP/ACadDoc.LSP/Some MNL file/Added to a CUI/loaded from an ARX/NetDLL/VBA/etc. And as was pointed out before - what about lisp code directly copied into the ACad command-line / lisp console? All I can think of as a "near-catch-all" method is to introduce a event which catches all loading of LSP/FAS/VLX files. Then saves a list of which defuns / setqs were loaded from which file. Unfortunately if you use a lisp reactor it's only going to catch load statements issued through something else than inside a LSP file - it won't catch a load from within the AcadDoc.LSP though. So I'm assuming this "solution" would only work if made into an ARX/NetDLL. Personally I prefer not relying on how the user loads the LSP file. I much prefer enforcing a specific method, so you don't run into such problems as this. Usually most would suggest you add the path to your support search paths - though that's not always an option (and if it's on a network could even impact performance negatively). My method of choice is to have a CUI loaded from the same folder (or folder structure) as the LSP/FAS/VLX files. Then use a custom FindFile function which checks if the CUI is loaded, if so searches that folder for the LSP file. This allows for a very simple way of "installing" your code by simply adding the CUI to those loaded. As an example look at the code used in the Caddons.MNL file (the Caddons:FindFile method): http://caddons.svn.sourceforge.net/viewvc/caddons/Caddons.MNL?revision=53&view=markup Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.