PGia Posted 6 hours ago Posted 6 hours ago 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 5 hours ago Posted 5 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 5 hours ago Posted 5 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 2 hours ago by mhupp 1 Quote
Steven P Posted 2 hours ago Posted 2 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 2 hours ago Posted 2 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.... 2 Quote
rlx Posted 2 hours ago Posted 2 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 2 hours ago by rlx 2 1 Quote
mhupp Posted 2 hours ago Posted 2 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 47 minutes ago by mhupp 1 1 Quote
Steven P Posted 2 hours ago Posted 2 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 2 hours ago by Steven P Quote
mhupp Posted 1 hour ago Posted 1 hour ago (edited) Didn't have the exe in the startapp line so maybe thats why? Edited 47 minutes ago by mhupp 1 Quote
PGia Posted 52 minutes ago Author Posted 52 minutes 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. 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.