Author Topic: Google inside of AutoCAD  (Read 1371 times)

0 Members and 1 Guest are viewing this topic.

nivuahc

  • Guest
Google inside of AutoCAD
« on: July 18, 2005, 05:15:23 PM »
I threw this together after a brief conversation with Mark so I'm sure it could be cleaned up and optimized quite a bit.

Anyway, this is what it does:

Type google in AutoCAD and you're presented with a crummy looking dialog box where you type in a file extension and some keywords to search for (i.e. DXF, RECEPTACLE). Click the "Google It!" button and your web browser is launched with the results.

What makes that special?

Not much, really. All it does is take advantage of Google's ability to search for specific file types. All of the links on the resulting page will be direct download links of the types of files you specified... so if you had used LSP as your file extension and SETQ as your search string, not only would you get a bajillion results, you could "right-click", "save as" each file and take a look at it's contents.

I wrote something similar in LUA and figured I'd do the same in LSP.

There are a couple of nifty (well, to me at least) little routines that I use in there and I thought that someone might like to toy around with it.

So, if you wanna give it a shot, here you go:

The LISP
Code: [Select]
(defun c:google (/)
  (defun googleit (file_type search_string /)
    (setq file_type (noleadspace file_type)
 file_type (notrailspace file_type)
 search_string (noleadspace search_string)
 search_string (notrailspace search_string)
 search_string (space_to_plus search_string)
 )
    (setq launch_url (strcat
      "http://www.google.com/search?hl=en&lr=&q=filetype%3A"
      file_type
      "+"
      search_string
      "&btnG=Search")
 )
    (launch_browser launch_url)
    )
 

 

  ;; launch the default web browser with the appropriate url
  (defun launch_browser (launch_url / )
    (if (/= (findfile "C:/Program Files/Mozilla Firefox/firefox.exe") nil)
      (startapp (strcat "C:/Program Files/Mozilla Firefox/firefox.exe " launch_url))
      (startapp (strcat "C:/Program Files/Internet Explorer/iexplore.exe " launch_url))
      )
    )
 
  ;;convert spaces in the target string to the plus symbol
  (defun space_to_plus (target_string / counter)
    (setq counter 1)
    (repeat (strlen target_string)
      (if (= (substr target_string counter 1) " ")
(setq target_string (strcat (substr target_string 1 (1- counter))
   "+"
   (substr target_string (1+ counter))
   )
     )
) ;_ end if
      (setq counter (1+ counter))
      ) ;_ end repeat
    target_string
    )
 
  ;;remove leading spaces
  (defun noleadspace (target_string /)
    (if target_string
      (while (= (substr target_string 1 1) " ")
(setq target_string (substr target_string 2))
) ;_ end while
      ) ;_ end if
    target_string
    )
 
  ;;remove trailing spaces
  (defun notrailspace (target_string /)
    (if target_string
      (while (and (/= target_string "") (= (substr target_string (strlen target_string)) " "))
(setq target_string (substr target_string 1 (1- (strlen target_string))))
) ;_ end while
      ) ;_ end if
    target_string
    )
 
(setq dcl_id (load_dialog "google.dcl"))
  (new_dialog "google" dcl_id)
  (setq xxx (start_dialog))
  (unload_dialog dcl_id)
  )


The DCL
Code: [Select]
google : dialog {
   label = "Google It!";
   : column {
      : text {
         label = "File Type Extension (i.e. DWG):";
         }
      : edit_box {        
         key = "file_type";
         width = 3;
         fixed_width = true;
      }
      : text {
         label = "Keyword (separate multiple keywords with spaces):";
         }
      : edit_box {
         key = "search_string";
         width = 60;
         fixed_width = true;
      }  
   }  
: row {
      : button {
         label = "Google It!";
         fixed_width = true;
         //alignment = centered;
         is_default = true;
         key = "google_it";
         mnemonic = "G";
         action = "(googleit (get_tile \"file_type\") (get_tile \"search_string\"))";
      }  
      : spacer { width = 1; }
      : button {
         label = "Done!";
      is_cancel = true;
      fixed_width = true;
      width = 6;
      }

   }  
   errtile;
}



you know, I haven't fooled with DCL in years... shows, don't it?  :P