Here's a lisp I found on autodesk's website a while back. It will search a directory of dwgs for text within a drawing. There are some changes/additions that would be nice if anyone can fix.
It doesn't search subdirectories.
There's no place to change partial word find, right now it seems to only find whole words.
I added the acet-u-pick directory a while ago, I think that was the only change I made, but it would be nice to have the option to default to the previously selected directory.
I've tried the find in vlide by changing the *.lsp to dwg. doesn't work as nice. Attached is the lisp.
;;;=========================================================================================================================================================
(defun Fndtxtstr_Error (msg)
(if
(not
(member msg
'("Function cancelled" "console break" "quit / exit abort")
)
)
(princ (strcat "\Error: " msg))
)
(Close_Dbx_Document DBX_DOC)
(setq *error* old_error old_error nil)
)
;;;=========================================================================================================================================================
(defun Open_Dbx_Document (DWG_NAME / DBX_DOCUMENT DBX_OPEN) ;Code provided by James Buzzbee
(if (/= DWG_NAME (vla-get-fullname (vla-get-activedocument (vlax-get-acad-Object))))
(progn
(cond
( (= (substr (getvar "ACADVER") 1 5) "15.06")
(setq DBX_DOCUMENT (vla-GetInterfaceObject (vlax-get-acad-Object) "ObjectDBX.AxDbDocument"))
(setq DBX_OPEN (vl-catch-all-apply 'vla-open (list DBX_DOCUMENT DWG_NAME)))
)
( (= (substr (getvar "ACADVER") 1 4) "16.0")
(setq DBX_DOCUMENT (vla-GetInterfaceObject (vlax-get-acad-Object) "ObjectDBX.AxDbDocument.16"))
(setq DBX_OPEN (vl-catch-all-apply 'vla-open (list DBX_DOCUMENT DWG_NAME)))
)
( (= (substr (getvar "ACADVER") 1 4) "16.1")
(setq DBX_DOCUMENT (vla-GetInterfaceObject (vlax-get-acad-Object) "ObjectDBX.AxDbDocument.16"))
(setq DBX_OPEN (vl-catch-all-apply 'vla-open (list DBX_DOCUMENT DWG_NAME)))
)
( (= (substr (getvar "ACADVER") 1 4) "16.2")
(setq DBX_DOCUMENT (vla-GetInterfaceObject (vlax-get-acad-Object) "ObjectDBX.AxDbDocument.16"))
(setq DBX_OPEN (vl-catch-all-apply 'vla-open (list DBX_DOCUMENT DWG_NAME)))
)
( (= (substr (getvar "ACADVER") 1 4) "17.0")
(setq DBX_DOCUMENT (vla-GetInterfaceObject (vlax-get-acad-Object) "ObjectDBX.AxDbDocument.17"))
(setq DBX_OPEN (vl-catch-all-apply 'vla-open (list DBX_DOCUMENT DWG_NAME)))
)
)
(if (vl-catch-all-error-p DBX_OPEN)
(setq DBX_DOCUMENT nil)
)
)
(alert "Can not open in DBX mode the drawing from which the call is made.")
)
DBX_DOCUMENT
)
;;;=========================================================================================================================================================
(defun Close_Dbx_Document (DBX_DOCUMENT) ;Code provided by James Buzzbee
(if (= (type DBX_DOCUMENT) 'VLA-OBJECT)(vlax-release-object DBX_DOCUMENT))
)
;;;=========================================================================================================================================================
(defun Find_Text_String (DWG TEXT_STRING CASE_SENSITIVE)
(if DWG
(progn
(setq DBX_DOC (Open_Dbx_Document DWG))
(vlax-for LAYOUT (vla-get-layouts DBX_DOC)
(vlax-for OBJECT (vla-get-Block LAYOUT)
(if
(and
(= (vla-get-objectname OBJECT) "AcDbText")
(if
(and CASE_SENSITIVE (not flag))
(wcmatch (vla-get-textstring OBJECT) TEXT_STRING)
(wcmatch (strcase (vla-get-textstring OBJECT)) (strcase TEXT_STRING))
)
)
(progn
(print "===============================")
(print (strcat "Drawing " DWG ":"))
(print (strcat "Found text string <" TEXT_STRING "> in " (vla-get-name LAYOUT)))
(print "===============================")
)
)
)
)
(Close_Dbx_Document DBX_DOC)
)
(alert (strcat "Could not find the drawing " DWG " ."))
)
(princ)
)
;;;=========================================================================================================================================================
(defun Find_Files_And_Run_In_Batch_Mode ($DIRECTORY $TEXT_STRING $CASE_SENSITIVE)
(setq old_error *error*)
(setq *error* Fndtxtstr_Error)
(foreach DRAWING_FILE (acad_strlsort (vl-directory-files $DIRECTORY "*.dwg" 1))
(if
(/=
(strcat $DIRECTORY "\\" DRAWING_FILE)
(strcat (getvar "dwgprefix")(getvar "dwgname"))
)
(progn
(prompt (strcat "\nProcessing file " (strcase DRAWING_FILE) " ..."))
(princ)
(Find_Text_String
(strcat $DIRECTORY "\\" DRAWING_FILE)
$TEXT_STRING
$CASE_SENSITIVE
)
)
)
)
(setq *error* old_error old_error nil)
)
;;;=========================================================================================================================================================
(defun c:FTS1 ()
(Find_Files_And_Run_In_Batch_Mode
(ACET-UI-PICKDIR "Select Directory to Search" "c:\\"); REPLACE HERE THE FOLDER TO CHECK FOR THE DRAWINGS
(getstring T "Enter text string to search for: ") ; TEXT STRING TO CHECK FOR
T ; CASE_SENSITIVE FLAG: IF IS T => MATCH CASE, IF IS NIL => DON'T MATCH THE CASE
)
(princ)
)
;;;=========================================================================================================================================================
(defun c:FTS2 () ;doesn't match case
(initget "Y N")
(setq flag (getstring "Find whole word [Y/N]: <N>"))
(if (= flag "")
(setq flag nil))
(Find_Files_And_Run_In_Batch_Mode
(ACET-UI-PICKDIR "Select Directory to Search" "c:\\"); REPLACE HERE THE FOLDER TO CHECK FOR THE DRAWINGS
(getstring T "Enter text string to search for: ") ; TEXT STRING TO CHECK FOR
nil) ; CASE_SENSITIVE FLAG: IF IS T => MATCH CASE, IF IS NIL => DON'T MATCH THE CASE
(princ)
)
;;;=========================================================================================================================================================
(prompt "\n*** FIND TEXT STRING VIA ODBX.LSP loaded. ***")
(prompt "\nType FNDTXTSTR1 to run in Case sensitive mode and FNDTXTSTR2 in Case insensitive mode.")
(princ)
;;;=========================================================================================================================================================