CAD Forums > CAD General
Find Text in a Closed Drawing
whdjr:
CAB,
I looked over your drawing and it keeps crashing when it comes across your block "20GOBLT01". I can't figure out why except that it says it has attributes, but when the program tries to get them its empty and therefore crashes. I think I can catch the error with
vl-catch-all-apply and then I'll post the revision.
That's a strange one. Anyone else got any ideas why a block would show a True flag for attributes, but then wouldn't have any? :? :? :?
whdjr:
CAB,
Here is the revised code that works on your file here in my office. I made a few modifications to show how many pieces of text, mtext, or attdefs you had in a drawing or wether that dwg was already open.
Give this one a spin and let me know. :wink:
--- Code: ---(vl-load-com)
(defun *error* (msg)
(princ "\nError: ")
(princ msg)
(princ)
(if (and dbxdoc (not (vlax-object-released-p dbxdoc)))
(vlax-release-object dbxdoc)
)
(gc)
(princ)
)
(defun DLLRegister (dll)
(startapp "regsvr32.exe" (strcat "/s \"" dll "\""))
)
(defun ProgID->ClassID (ProgID)
(vl-registry-read
(strcat "HKEY_CLASSES_ROOT\\" progid "\\CLSID")
)
)
(defun DBX-Register (/)
(setq classname "ObjectDBX.AxDbDocument")
(cond
((ProgID->ClassID classname))
((and
(setq server (findfile "AxDb15.dll"))
(DLLRegister server)
(ProgID->ClassID classname)
)
(ProgID->ClassID classname)
)
((not (setq server (findfile "AxDb15.dll")))
(alert
"Error: Cannot locate ObjectDBX Type Library (AxDb15.dll)..."
)
)
(T
(DLLRegister "ObjectDBX.AxDbDocument")
(or
(ProgID->ClassID "ObjectDBX.AxDbDocument")
(alert
"Error: Failed to register ObjectDBX ActiveX services..."
)
)
)
)
)
(defun findphrase (phrase document / txtcount mtxtcount attcount oName)
(setq txtcount 0
mtxtcount 0
attcount 0
)
(vlax-for item (vla-get-modelspace document)
(setq oName (vla-get-ObjectName item))
(cond ((eq oName "AcDbText")
(if (vl-string-search phrase (vla-get-textstring item))
(setq txtcount (1+ txtcount))
)
)
((eq oName "AcDbMText")
(if (vl-string-search phrase (vla-get-textstring item))
(setq mtxtcount (1+ mtxtcount))
)
)
((and (eq oName "AcDbBlockReference")
(eq (vla-get-hasattributes item) :vlax-true)
)
(foreach for-item (get_atts item)
(if (vl-string-search phrase (vla-get-textstring for-item))
(setq attcount (1+ attcount))
)
)
)
)
)
(list txtcount mtxtcount attcount)
)
(defun get_atts (obj / val)
(if (vl-catch-all-error-p
(vl-catch-all-apply
'(lambda ()
(setq val (vlax-safearray->list
(vlax-variant-value
(vla-getattributes obj)
)
)
)
)
)
)
nil
val
)
)
(defun c:tfar (/ file files str dbxdoc of lst wil classname)
(setq file "")
(while (setq file (getfiled "Select a file to replace text in" file "dwg" 128))
(setq files (cons file files))
)
(cond ((not files) (princ "No files were selected."))
((not (setq str (getstring T "Enter search phrase? ")))
(princ "\nSearch phrase is missing. ")
)
((not (DBX-Register)) (princ "Unable to load ObjectDBX."))
((not (setq dbxdoc (vla-GetInterfaceObject
(vlax-get-acad-object)
classname
)
)
)
(princ "Unable to load ObjectDBX.")
)
(T
(foreach f (reverse files)
(setq of (vl-catch-all-apply
'(lambda ()
(vlax-invoke-method dbxdoc 'open f)
)
)
lst (if (vl-catch-all-error-p of)
(list f "File was read only. ")
(list f (findphrase str dbxdoc))
)
wil (cons lst wil)
)
)
)
)
(if (and dbxdoc (not (vlax-object-released-p dbxdoc)))
(vlax-release-object dbxdoc)
)
(gc)
(textscr)
(mapcar '(lambda (x)
(princ
(strcat "\n"
(car x)
(cond ((eq (type (cadr x)) 'LIST)
(apply 'strcat
(mapcar '(lambda (y z)
(strcat "\n" (itoa y) z)
)
(cadr x)
'(" text entities matched your phrase."
" mtext entities matched your phrase."
" attribute reference entities matched your phrase.\n"
)
)
)
)
(T (strcat "\n" (cadr x))
)
)
)
)
wil
)
(princ)
)
--- End code ---
CAB:
--- Quote from: whdjr ---CAB,
I looked over your drawing and it keeps crashing when it comes across your block "20GOBLT01". I can't figure out why except that it says it has attributes, but when the program tries to get them its empty and therefore crashes. I think I can catch the error with
vl-catch-all-apply and then I'll post the revision.
That's a strange one. Anyone else got any ideas why a block would show a True flag for attributes, but then wouldn't have any? :? :? :?
--- End quote ---
Will,
The block is one created by Arch-T. The attribute has a tag 'Go-Bolt' which
displays on the screen and was used to make a slide so the slide has a
visible label in the original drawing but will not be displayed when inserted
as the attribute is empty.
That is my understanding of it anyway.
CAB
CAB:
Command: tfar
Enter search phrase? trusses @16" oc
That seemed to work, although case sensitive.
--- Quote ---Command: tfar
Enter search phrase? trusses @ 16" oc
C:\Program Files\ACAD2000\=Active Projects\Steve Carter\4225 Morrison\4225
Morrison Master 1.DWG
0 text entities matched your phrase.
0 mtext entities matched your phrase.
0 attribute reference entities matched your phrase.
Command:
Command:
Command:
Command: _open
Command: tfar
Enter search phrase? PRE MFG TRUSSES @ 16" OC
C:\Program Files\ACAD2000\=Active Projects\Steve Carter\4225 Morrison\4225
Morrison Master 1.DWG
3 text entities matched your phrase.
0 mtext entities matched your phrase.
0 attribute reference entities matched your phrase.
Command:
Command: PRE PREVIEW
Press ESC or ENTER to exit, or right-click to display shortcut menu.
Command: tfar
Enter search phrase? TRUSSES @ 16" OC
C:\Program Files\ACAD2000\=Active Projects\Steve Carter\4225 Morrison\4225
Morrison Master 1.DWG
3 text entities matched your phrase.
0 mtext entities matched your phrase.
0 attribute reference entities matched your phrase.
Command:
--- End quote ---
Message when file was open:
--- Quote ---Command: tfar
Enter search phrase? trusses @16" oc
C:\Program Files\ACAD2000\=Active Projects\Steve Carter\4225 Morrison\4225
Morrison Master 1.DWG
File was read only.
--- End quote ---
whdjr:
Glad that worked for you.
Navigation
[0] Message Index
[*] Previous page
Go to full version