PGia Posted yesterday at 11:19 AM Posted yesterday at 11:19 AM Hello again A quick question (I assume this will be an easy answer for the experts on this forum): I often need to search for and open various types of files, primarily in AutoCAD directories but also in others. Is there a quick way to search for and open any file in an editor using a custom Lisp command? Thanks in advance Quote
CyberAngel Posted 23 hours ago Posted 23 hours ago If it's not exclusively AutoCAD files, you may be better off using a system tool. What kinds of files would you be looking for? What parameters would you be searching with? What editors would you be opening them with? The more you can tell us, the better we can help you. 1 Quote
mhupp Posted 23 hours ago Posted 23 hours ago (edited) Had a command DIR to start in the folder of the active drawing would open the save prompt like window to allow you to select the file you want. pretty sure if you feed the path to explorer it will use the default program to open the file. (defun C:DIR ( / filePath) (setq dwgPath (getvar "DWGPREFIX")) (setq filePath (getfiled "Select a File to Open" dwgPath "*" 0)) ;limit what types you see by changing "*" (if filePath (progn (startapp "explorer.exe" filePath) (princ (strcat "\nOpening: " filePath)) ) (princ "\nNo file selected.") ) (princ) ) -edit You can also hard code where it stats in like if your documents are in a network drive. (setq filePath (getfiled "Select a Spec File" "C:\\Project\\spec\\" "PDF" 0)) ;look in spec folder for all pdf's Edited 21 hours ago by mhupp 2 Quote
Steven P Posted 21 hours ago Posted 21 hours ago This will search a location for a file type, in the example searching for LISP files in c:\MyLocation\Here - remember to use a double backslash in any location, and return a list of files names + extensions (also folders if the file type is *.*). (setq myfiles (vl-directory-files "C:\\MyLocation\\Here" "*.lsp" nil)) You could do a search of this list to check if your required file is in there As MHUPP use startapp to open the file, here opens the file in variable Lispfile with notepad (startapp "notepad" Lispfile) MHUPP example was for explorer - I didn't know that method would work for any file type to open the default programme. For the first line here, your file path could be contained in a list, looping through each list item (location) until you find the file you want - could search a few locations if you knew them and want to hardcode them in the LISP, and if fails to find them there use MHUPPs 'getfiled' line for the user to select a folder or file. Use an if, cond or while loop to open the file where it finds it and stop the rest of the loop from looping 1 1 Quote
Steven P Posted 20 hours ago Posted 20 hours ago also shell commands - I've only used that once though: (defun c:GetGoogle ( / SearchTerm PageBase) (setq SearchTerm (getstring "Enter Serch Term: [use '+' between terms] ")) ;; get search term, '+' between words (setq PageBase "(command \"shell\" \"start microsoft-edge:http://google.com/search?q=") ;; google address (setq Page (strcat PageBase SearchTerm "\")" )) ;; google + search term address (eval (read Page)) ;; open 'Page' ) Guess what this does.... 3 Quote
rlx Posted 20 hours ago Posted 20 hours ago (edited) actually quite nice Steven , think I'm gonna add this to one of my toolbars (if there's still room that is...) for opening things I also like : https://lee-mac.com/open.html Edited 20 hours ago by rlx 2 1 Quote
mhupp Posted 20 hours ago Posted 20 hours ago (edited) @Steven P See what this does. again will use default browser. (startapp "explorer.exe" "https://www.youtube.com/watch?v=dQw4w9WgXcQ") So above can be (defun c:GetGoogle ( / Search Page) (setq Search (getstring "Enter Serch Term: [use '+' between terms] ")) ;; get search term, '+' between words (setq Page (strcat "https://www.google.com/search?q=" Search)) ;; google + search term address (startapp "explorer.exe" page) ) -edit didn't have the exe Edited 19 hours ago by mhupp 1 1 1 Quote
Steven P Posted 20 hours ago Posted 20 hours ago (edited) Didn't quite work for me - opened explorer and went to a folder - not sure why yet ... actually, take away the '/watch?v....." and it works, probably just your dodgy youtube viewing habits.. Edited 20 hours ago by Steven P 1 Quote
mhupp Posted 19 hours ago Posted 19 hours ago (edited) Didn't have the exe in the startapp line so maybe thats why? Edited 19 hours ago by mhupp 1 1 Quote
PGia Posted 19 hours ago Author Posted 19 hours ago 4 hours ago, CyberAngel said: If it's not exclusively AutoCAD files, you may be better off using a system tool. What kinds of files would you be looking for? What parameters would you be searching with? What editors would you be opening them with? The more you can tell us, the better we can help you. Thanks for the answers. They're really very interesting. And I really liked @Steven P's Lisp for searching on Google In response to Ciberangel, I must say that I often need to edit acad.lsp and other AutoCAD support files, and I really feel like I'm wasting a lot of time doing that. Additionally, I almost always need to open Access databases that contain information related to the drawings I manage. I also manage photo banks with standardized names that I need to reference on the fly in my drawings. For these reasons, a tool to search and open these files will save me a lot of time. 1 Quote
PGia Posted 17 hours ago Author Posted 17 hours ago Thanks to RLX for recommending Lee Mac's code (Lee Mac: thanks for sharing it) I just figured out how it works, and I think it's pretty close to what I need I guess I should create a command to run that code whenever I need it. Quote
rlx Posted 15 hours ago Posted 15 hours ago I did write something once to find and launch documents but its a little over the top probably. But Bigal also had a good suggestion , a program called everything. 2 1 Quote
BIGAL Posted 13 hours ago Posted 13 hours ago I use Everything all the time it indexes hard drives and finds a file instantly. Re Access, Word, Excel and Libre office all of these can be accessed from CAD I use Bricscad. You can for say Access not only open but actually get at the data, most common being Excel get and put. If you have a few known files you want to open all the time can either make a defun for each and load on startup or my preferred would be a sub menu in a POP menu with the file names as the description. As mentioned already using notepad is shown how in ACAD.PGP as an already defined option. 1 Quote
Lee Mac Posted 2 hours ago Posted 2 hours ago I would also vote for Everything - it's ridiculously fast. Quote
GLAVCVS Posted 33 minutes ago Posted 33 minutes ago (edited) @PGia In case you don't mind including all the file locations you need to reference in AutoCAD's "SupportPaths" (other external paths could also be considered, but would require more code), there is another option, unorthodox but disruptive: type the name of the file to open directly into the command line (but with a small convention) I think some of the participants in this thread know what I'm talking about. If not, I'll explain it with a little code when I get home. Edited 6 minutes ago by GLAVCVS 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.