Jump to content

Recommended Posts

Posted

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

Posted

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.

  • Like 1
Posted (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 by mhupp
  • Like 1
Posted

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

  • Like 1
  • Agree 1
Posted

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....

  • Like 2
Posted (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 by rlx
  • Like 2
  • Funny 1
Posted (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 by mhupp
  • Like 1
  • Funny 1
  • Thanks 1
Posted (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 by Steven P
  • Thanks 1
Posted (edited)

Didn't have the exe in the startapp line so maybe thats why? 

Edited by mhupp
  • Like 1
  • Thanks 1
Posted
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.

  • Thanks 1
Posted

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.

Posted

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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...