Author Topic: search directorys for text in dwg  (Read 6194 times)

0 Members and 1 Guest are viewing this topic.

cadmoogle

  • Guest
Re: search directorys for text in dwg
« Reply #15 on: August 13, 2009, 08:08:04 AM »
I know why it's repeating, because it's finding more than one instance. Is it possible to make it count the number of instances, or just show only one? 

cadmoogle

  • Guest
Re: search directorys for text in dwg
« Reply #16 on: August 13, 2009, 10:10:43 AM »
Okay, so I got it to write to a text file  8-)...

but I messed something else up.  :evil:


Quote
===============================
Drawing C:\Temp\Test\B10-1.dwg:
Found text string <REDRAW> in Model
===============================
===============================
Drawing C:\Temp\Test\B10-1.dwg:
Found text string <REDRAW> in Model
===============================
.....
and you keeps repeating..



Here is the section I modified.

Code: [Select]
(defun Find_Text_String (DWG TEXT_STRING CASE_SENSITIVE)

  (if (setq DBX_DOC (Open_Dbx_Document DWG))
    (progn
      (vlax-for LAYOUT (vla-get-layouts DBX_DOC)
        (vlax-for OBJECT (vla-get-Block LAYOUT)
          (if
            (and
              (vl-position (vla-get-objectname OBJECT) '("AcDbText" "AcDbMText"))
              (if CASE_SENSITIVE
                (wcmatch (vla-get-textstring OBJECT) (strcat "*" TEXT_STRING "*"))
                (wcmatch (strcase (vla-get-textstring OBJECT))
                         (strcat "*" (strcase TEXT_STRING) "*")
                )
              )
            )
  (setq filename (open "C:\\Temp\\Test\\test.txt" "w")) ;;Begin here add by cadmoogle, changed it to write-line
             (progn
               (write-line "===============================" filename)
               (write-line (strcat "Drawing " DWG ":" ) filename)
               (write-line
                 (strcat "Found text string <" TEXT_STRING "> in " (vla-get-name LAYOUT )) filename
               )
               (write-line "===============================" filename) ;;End add here by cadoogle
             )
          )
        )
      )
      (Close_Dbx_Document DBX_DOC)
    )
    (princ
      (strcat "\n*  Could not open drawing " (vl-filename-base DWG) ".DWG")
    )
  )
  (princ)
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: search directorys for text in dwg
« Reply #17 on: August 13, 2009, 11:08:35 AM »
I did a quick rewrite to add output file.

Requires another parameter when called!!
Code: [Select]
(defun c:test ()
  (Find_Files_And_Run_In_Batch_Mode
    "C:\\Program Files\\ACAD2000\\Temp"; REPLACE HERE THE FOLDER TO CHECK FOR THE DRAWINGS
    "REDRAW"                           ; TEXT STRING TO CHECK FOR
    nil                                ; CASE_SENSITIVE FLAG: IF IS T => MATCH CASE, IF IS NIL => DON'T MATCH THE CASE
    [color=red]t   ; output results to file[/color]
  )
  (princ)
)

Code: [Select]
;;  Modified by CAB 08.13.09

;;;===============================================================================================================
(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)
  (if (= DWG_NAME (vla-get-fullname (vla-get-activedocument (vlax-get-acad-Object))))
    (princ "\nCan not open in DBX mode the drawing from which the call is made.")
      (if (and (setq DBX_DOCUMENT (GetDBXInterface))
               (vl-catch-all-error-p
                 (setq DBX_OPEN (vl-catch-all-apply
                                     'vla-open (list DBX_DOCUMENT DWG_NAME)))
                ))
        (setq DBX_DOCUMENT nil)
    )
  )
  DBX_DOCUMENT
)
;;;=============================================================================================================
;;  CAB 07/15/2008, update 8.11.09
(defun GetDBXInterface (/ Vers)
  (cond 
   ((< (setq Vers (substr (getvar "acadver") 1 2)) "16")
    (vla-GetInterfaceObject (vlax-get-acad-object) "ObjectDBX.AxDbDocument"))
   ((<  (substr (getvar "acadver") 1 4) "17.2")
    (vla-GetInterfaceObject (vlax-get-acad-object) "ObjectDBX.AxDbDocument.16"))
   (t (vla-GetInterfaceObject (vlax-get-acad-object)
         (strcat "ObjectDBX.AxDbDocument."(substr (getvar "acadver") 1 2))))
  )
)

;;;=============================================================================================================
(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 / sName cnt tmp)

  (if (setq DBX_DOC (Open_Dbx_Document DWG))
    (progn
      (vlax-for LAYOUT (vla-get-layouts DBX_DOC)
        (setq sname (vla-get-name layout))
        (vlax-for OBJECT (vla-get-Block LAYOUT)
          (if
            (and
              (vl-position (vla-get-objectname OBJECT) '("AcDbText" "AcDbMText"))
              (if CASE_SENSITIVE
                (wcmatch (vla-get-textstring OBJECT) (strcat "*" TEXT_STRING "*"))
                (wcmatch (strcase (vla-get-textstring OBJECT))
                         (strcat "*" (strcase TEXT_STRING) "*")
                )
              )
            )
             (cond
               ((null cnt) (setq cnt (list (cons sname 1))))
               ((setq tmp (assoc sName cnt))
                (setq cnt (subst (cons sname (1+ (cdr tmp))) tmp cnt)))
               (t (setq cnt (cons (cons sname 1) cnt)))
             )
          )
        )
      )
      (Close_Dbx_Document DBX_DOC)
      (if cnt
        (progn
          (cond (fn
           (write-line "===============================" fn)
           (write-line (strcat "Drawing " DWG ":") fn)
           (write-line (strcat "Found text string < " TEXT_STRING " >") fn)
           (foreach tmp cnt
            (write-line (strcat "  count= " (itoa (cdr tmp)) "  Layout= " (car tmp)) fn))
           (write-line "===============================" fn)
          ))
          (print "===============================")
          (print (strcat "Drawing " DWG ":"))
          (print (strcat "Found text string < " TEXT_STRING " >"))
          (foreach tmp cnt
           (print (strcat "  count= " (itoa (cdr tmp)) "  Layout= " (car tmp)))
          )
          (print "===============================")
        )
      )
    )
    (princ (strcat "\n*  Could not open drawing " (vl-filename-base DWG) ".DWG"))
  )
  (princ)
)
;;;===========================================================================================================
(defun Find_Files_And_Run_In_Batch_Mode ($DIRECTORY $TEXT_STRING $CASE_SENSITIVE FileOut / fn of)

  ;;  FileOut if not nil write results to the OutPut File "FindStringResults"
  ;;  in the ACAD root folder
  (setq old_error *error*)
  (setq *error* Fndtxtstr_Error)
  (if (and FileOut (setq fn (findfile "ACAD.EXE")))
    (setq fn (open (setq of (strcat (vl-filename-directory fn) "\\FindStringResults.txt")) "w"))
  )

  (textscr)
  (cond (fn
  (write-line "---------------------------------" fn)
  (write-line "  -=<  Find Text in Progress  >=-" fn)
  (write-line "---------------------------------" fn)
  ))
  (princ "---------------------------------")
  (princ "\n  -=<  Find Text in Progress  >=-")
  (princ "\n---------------------------------")
  (if of (princ (strcat "\n  Output File " of)))
  (foreach DRAWING_FILE (acad_strlsort (vl-directory-files $DIRECTORY "*.dwg" 1))
    (if (/= (strcat $DIRECTORY "\\" DRAWING_FILE)
            (strcat (getvar "dwgprefix") (getvar "dwgname"))
        )
      (progn
        (if fn
          (write-line (strcat "|-> Processing file " (strcase DRAWING_FILE) " ...") fn)
        )
        (princ (strcat "\n|-> Processing file " (strcase DRAWING_FILE) " ..."))
        (Find_Text_String (strcat $DIRECTORY "\\" DRAWING_FILE) $TEXT_STRING $CASE_SENSITIVE)
      )
    )
  )
  (cond (fn
  (write-line "-------------------------------" fn)
  (write-line "  -=<  Find Text Completed  >=-" fn)
  (write-line "-------------------------------" fn)
  (close fn)
  ))
  (princ "\n-------------------------------")
  (princ "\n  -=<  Find Text Completed  >=-")
  (princ "\n-------------------------------")
  (setq *error* old_error
        old_error nil
  )
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

cadmoogle

  • Guest
Re: search directorys for text in dwg
« Reply #18 on: August 13, 2009, 11:47:59 AM »
Thanks again CAB, it works and finishes the write, but displays the following message at the end of the command.

Code: [Select]
|-> Processing file Z6-3.DWG ...Error: too many arguments; error: An error has
occurred inside the *error* functionnull interface pointer: #<VLA-OBJECT
00000000>

I went back and looked at your code, what does the 'fn' do for the code? I'm guessing 'cond' means condition... I could be wrong. I'm getting ready to take some VB and Java classes, so hopefully they will help with writing LISP.

Thanks again for the help,
Daniel

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: search directorys for text in dwg
« Reply #19 on: August 13, 2009, 11:59:27 AM »
Yes cond is the condition statement & fn is the Text File pointer.
Could not reproduce the error. Try a restart of ACAD & report back if the error continues.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

cadmoogle

  • Guest
Re: search directorys for text in dwg
« Reply #20 on: August 13, 2009, 12:53:22 PM »
Yes cond is the condition statement & fn is the Text File pointer.
Could not reproduce the error. Try a restart of ACAD & report back if the error continues.


I restarted, and it still produced the same message.

Quote
Command: test
---------------------------------
  -=<  Find Text in Progress  >=-
---------------------------------
  Output File C:\Program Files\AutoCAD Map 3D 2010\FindStringResults.txt
|-> Processing file BLOCKS.DWG ...Loading AEC Base...
Loading AEC Base Extended...
Loading AEC Base UI...
Loading AECC Base...
Loading AEC Project Base...
Loading AEC Schedule Data...
Loading AEC Architectural Base...
Loading AEC Structural Base...
Loading AEC Area Base...
Loading AEC Dimensions Base...
Loading AEC Schedule...
Loading AECC Land...
Loading AECC Subentity Selection...
Loading AECC Plan Production...

|-> Processing file KEYSTONE.DWG ...
|-> Processing file KEYSTONE_GIS.DWG ...
|-> Processing file KEYSTONE_SOVERA.DWG ...
|-> Processing file KEYSTONE_SOVERA2.DWG ...
|-> Processing file KEYSTONE2.DWG ...
|-> Processing file KNIGHTBOXX.DWG ...
|-> Processing file MAP.DWG ...Loading AECC Pipe Part...
Loading AECC QTO......
Loading AECC Pipe Network...
Loading AECC Roadway...
Loading AECC Survey...

|-> Processing file OVERALL EASEMENT MAP.DWG ...Error: too many arguments;
error: An error has occurred inside the *error* functionnull interface pointer:
#<VLA-OBJECT 00000000>

Command:

It probably means I formatted something wrong.

Code: [Select]
;;  Modified by CAB 08.13.09

;;;===============================================================================================================
(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)
  (if (= DWG_NAME (vla-get-fullname (vla-get-activedocument (vlax-get-acad-Object))))
    (princ "\nCan not open in DBX mode the drawing from which the call is made.")
      (if (and (setq DBX_DOCUMENT (GetDBXInterface))
               (vl-catch-all-error-p
                 (setq DBX_OPEN (vl-catch-all-apply
                                     'vla-open (list DBX_DOCUMENT DWG_NAME)))
                ))
        (setq DBX_DOCUMENT nil)
    )
  )
  DBX_DOCUMENT
)
;;;=============================================================================================================
;;  CAB 07/15/2008, update 8.11.09
(defun GetDBXInterface (/ Vers)
  (cond 
   ((< (setq Vers (substr (getvar "acadver") 1 2)) "16")
    (vla-GetInterfaceObject (vlax-get-acad-object) "ObjectDBX.AxDbDocument"))
   ((<  (substr (getvar "acadver") 1 4) "17.2")
    (vla-GetInterfaceObject (vlax-get-acad-object) "ObjectDBX.AxDbDocument.16"))
   (t (vla-GetInterfaceObject (vlax-get-acad-object)
         (strcat "ObjectDBX.AxDbDocument."(substr (getvar "acadver") 1 2))))
  )
)

;;;=============================================================================================================
(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 / sName cnt tmp)

  (if (setq DBX_DOC (Open_Dbx_Document DWG))
    (progn
      (vlax-for LAYOUT (vla-get-layouts DBX_DOC)
        (setq sname (vla-get-name layout))
        (vlax-for OBJECT (vla-get-Block LAYOUT)
          (if
            (and
              (vl-position (vla-get-objectname OBJECT) '("AcDbText" "AcDbMText"))
              (if CASE_SENSITIVE
                (wcmatch (vla-get-textstring OBJECT) (strcat "*" TEXT_STRING "*"))
                (wcmatch (strcase (vla-get-textstring OBJECT))
                         (strcat "*" (strcase TEXT_STRING) "*")
                )
              )
            )
             (cond
               ((null cnt) (setq cnt (list (cons sname 1))))
               ((setq tmp (assoc sName cnt))
                (setq cnt (subst (cons sname (1+ (cdr tmp))) tmp cnt)))
               (t (setq cnt (cons (cons sname 1) cnt)))
             )
          )
        )
      )
      (Close_Dbx_Document DBX_DOC)
      (if cnt
        (progn
          (cond (fn
           (write-line "===============================" fn)
           (write-line (strcat "Drawing " DWG ":") fn)
           (write-line (strcat "Found text string < " TEXT_STRING " >") fn)
           (foreach tmp cnt
            (write-line (strcat "  count= " (itoa (cdr tmp)) "  Layout= " (car tmp)) fn))
           (write-line "===============================" fn)
          ))
          (print "===============================")
          (print (strcat "Drawing " DWG ":"))
          (print (strcat "Found text string < " TEXT_STRING " >"))
          (foreach tmp cnt
           (print (strcat "  count= " (itoa (cdr tmp)) "  Layout= " (car tmp)))
          )
          (print "===============================")
        )
      )
    )
    (princ (strcat "\n*  Could not open drawing " (vl-filename-base DWG) ".DWG"))
  )
  (princ)
)
;;;===========================================================================================================
(defun Find_Files_And_Run_In_Batch_Mode ($DIRECTORY $TEXT_STRING $CASE_SENSITIVE FileOut / fn of)

  ;;  FileOut if not nil write results to the OutPut File "FindStringResults"
  ;;  in the ACAD root folder
  (setq old_error *error*)
  (setq *error* Fndtxtstr_Error)
  (if (and FileOut (setq fn (findfile "ACAD.EXE")))
    (setq fn (open (setq of (strcat (vl-filename-directory fn) "\\FindStringResults.txt")) "w"))
  )

  (textscr)
  (cond (fn
  (write-line "---------------------------------" fn)
  (write-line "  -=<  Find Text in Progress  >=-" fn)
  (write-line "---------------------------------" fn)
  ))
  (princ "---------------------------------")
  (princ "\n  -=<  Find Text in Progress  >=-")
  (princ "\n---------------------------------")
  (if of (princ (strcat "\n  Output File " of)))
  (foreach DRAWING_FILE (acad_strlsort (vl-directory-files $DIRECTORY "*.dwg" 1))
    (if (/= (strcat $DIRECTORY "\\" DRAWING_FILE)
            (strcat (getvar "dwgprefix") (getvar "dwgname"))
        )
      (progn
        (if fn
          (write-line (strcat "|-> Processing file " (strcase DRAWING_FILE) " ...") fn)
        )
        (princ (strcat "\n|-> Processing file " (strcase DRAWING_FILE) " ..."))
        (Find_Text_String (strcat $DIRECTORY "\\" DRAWING_FILE) $TEXT_STRING $CASE_SENSITIVE)
      )
    )
  )
  (cond (fn
  (write-line "-------------------------------" fn)
  (write-line "  -=<  Find Text Completed  >=-" fn)
  (write-line "-------------------------------" fn)
  (close fn)
  ))
  (princ "\n-------------------------------")
  (princ "\n  -=<  Find Text Completed  >=-")
  (princ "\n-------------------------------")
  (setq *error* old_error
        old_error nil
  )
)
(defun c:test ()
  (Find_Files_And_Run_In_Batch_Mode
    "C:\\Temp\\"; REPLACE HERE THE FOLDER TO CHECK FOR THE DRAWINGS
    "REDRAW"                           ; TEXT STRING TO CHECK FOR
    nil                                ; CASE_SENSITIVE FLAG: IF IS T => MATCH CASE, IF IS NIL => DON'T MATCH THE CASE
    t   ; output results to file
  )
  (princ)
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: search directorys for text in dwg
« Reply #21 on: August 13, 2009, 01:11:04 PM »
Replace this code
Code: [Select]
(defun Close_Dbx_Document  (DBX_DOCUMENT) ;Code provided by James Buzzbee
  (if (= (type DBX_DOCUMENT) 'VLA-OBJECT)(vlax-release-object DBX_DOCUMENT))
)

with this
Code: [Select]
(defun Close_Dbx_Document  (DBX_DOCUMENT)
  (if (and (= (type DBX_DOCUMENT) 'VLA-OBJECT)
             (not (vlax-object-released-p DBX_DOCUMENT)))
     (vlax-release-object DBX_DOCUMENT))
)
does that change the message?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

cadmoogle

  • Guest
Re: search directorys for text in dwg
« Reply #22 on: August 13, 2009, 02:32:34 PM »
Replace this code
Code: [Select]
(defun Close_Dbx_Document  (DBX_DOCUMENT) ;Code provided by James Buzzbee
  (if (= (type DBX_DOCUMENT) 'VLA-OBJECT)(vlax-release-object DBX_DOCUMENT))
)

with this
Code: [Select]
(defun Close_Dbx_Document  (DBX_DOCUMENT)
  (if (and (= (type DBX_DOCUMENT) 'VLA-OBJECT)
             (not (vlax-object-released-p DBX_DOCUMENT)))
     (vlax-release-object DBX_DOCUMENT))
)
does that change the message?


Now it says...

Quote
---------------------------------
  -=<  Find Text in Progress  >=-
---------------------------------
  Output File C:\Program Files\AutoCAD Map 3D 2010\FindStringResults.txt
|-> Processing file BLOCKS.DWG ...Loading AEC Base...
Loading AEC Base Extended...
Loading AEC Base UI...
Loading AECC Base...
Loading AEC Project Base...
Loading AEC Schedule Data...
Loading AEC Architectural Base...
Loading AEC Structural Base...
Loading AEC Area Base...
Loading AEC Dimensions Base...
Loading AEC Schedule...
Loading AECC Land...
Loading AECC Subentity Selection...
Loading AECC Plan Production...

|-> Processing file KEYSTONE.DWG ...
|-> Processing file KEYSTONE_GIS.DWG ...
|-> Processing file KEYSTONE_SOVERA.DWG ...
|-> Processing file KEYSTONE_SOVERA2.DWG ...
|-> Processing file KEYSTONE2.DWG ...
|-> Processing file KNIGHTBOXX.DWG ...
|-> Processing file MAP.DWG ...Loading AECC Pipe Part...
Loading AECC QTO......
Loading AECC Pipe Network...
Loading AECC Roadway...
Loading AECC Survey...

|-> Processing file OVERALL EASEMENT MAP.DWG ...Error: too many arguments

It appears to finish though.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: search directorys for text in dwg
« Reply #23 on: August 13, 2009, 02:47:56 PM »
I only fixed one of the problems and it is not finishing.

Load the routine from VLIDE so the error will send you back to VLIDE.
Then in the console window enter (vl-bt)
report you findings.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.