View Full Version : Take existing drawings and find all "|" and replace with "1/4"
sschwartz
2006-07-17, 07:08 PM
Question:
We are changing the standard font from freehand.shx to simplex.shx in our office. The problem is, that there are a certain number of keyboard "symbols" in the freehand font _ | { \ } [ ] < > ~ ' ; that when typed in, make up a number of fractions, and a few other symbols. SOOO, when we use simplex, the fraction 1/4 converts to a | . (Kind of difficult to call out a conduit size as that...)
I have tried find and replace, and quickselect, etc. It will not read the 'symbol' properly. Any ideas of a way to take existing drawings and find all "|" and replace with "1/4".
I have attached the font we are converting from...
Terry Cadd
2006-07-17, 09:18 PM
I tried using AutoCAD's Find with the FreeHand.shx font and it worked ok on our system. Here is a function that I wrote to be used in programs, but it can be run on the command line using the following syntax:
(FindReplaceAll "|" "1/4")
Use it with care, because it does exactly what it's named.
Terry Cadd
;-------------------------------------------------------------------------------
; FindReplaceAll - Changes Text, Mtext, Dimensions and Attribute Block entities
; that have a Find$ string with a Replace$ string.
; Arguments: 2
; Find$ = Phrase string to find
; Replace$ = Phrase to replace it with
; Syntax: (FindReplaceAll "|" "1/4")
; Returns: Updates Text, Mtext, Dimension and Attribute Block entities
;-------------------------------------------------------------------------------
(defun FindReplaceAll (Find$ Replace$ / BlkEntList@ BlkEntName^ BlkEntType$ Cnt#
DimEntList@ DimEntName^ DimEntType$ EntList@ EntName^ EntType$ FindReplace:
Mid$ Mid2$ NewText$ Num# Replace$ SS& Text$)
;-----------------------------------------------------------------------------
; FindReplace: - Returns Str$ with Find$ changed to Replace$
; Arguments: 3
; Str$ = Text string
; Find$ = Phrase string to find
; Replace$ = Phrase to replace Find$ with
; Returns: Returns Str$ with Find$ changed to Replace$
;-----------------------------------------------------------------------------
(defun FindReplace: (Str$ Find$ Replace$ / Cnt# FindLen# Loop Mid$ NewStr$ ReplaceLen#)
(setq Loop t Cnt# 1 NewStr$ Str$ FindLen# (strlen Find$) ReplaceLen# (strlen Replace$))
(while Loop
(setq Mid$ (substr NewStr$ Cnt# FindLen#))
(if (= Mid$ Find$)
(setq NewStr$ (strcat (substr NewStr$ 1 (1- Cnt#)) Replace$ (substr NewStr$ (+ Cnt# FindLen#)))
Cnt# (+ Cnt# ReplaceLen#)
);setq
(setq Cnt# (1+ Cnt#))
);if
(if (= Mid$ "") (setq Loop nil))
);while
NewStr$
);defun FindReplace:
;-----------------------------------------------------------------------------
; Start of Main function
;-----------------------------------------------------------------------------
(if (and (= (type Find$) 'STR)(= (type Replace$) 'STR)(/= Find$ ""))
(progn
(if (setq SS& (ssget "x" (list '(-4 . "<AND")'(-4 . "<OR")'(0 . "TEXT")'(0 . "MTEXT")'(0 . "DIMENSION")'(0 . "INSERT")'(-4 . "OR>")(cons 410 (getvar "CTAB"))'(-4 . "AND>"))))
(progn
(command "UNDO" "BEGIN")
(setq Cnt# 0)
(repeat (sslength SS&)
(setq EntName^ (ssname SS& Cnt#)
EntList@ (entget EntName^)
EntType$ (cdr (assoc 0 EntList@))
Text$ (cdr (assoc 1 EntList@))
);setq
(if (= EntType$ "INSERT")
(if (assoc 66 EntList@)
(progn
(while (/= (cdr (assoc 0 EntList@)) "SEQEND")
(setq EntList@ (entget EntName^))
(if (= (cdr (assoc 0 EntList@)) "ATTRIB")
(progn
(setq Text$ (cdr (assoc 1 EntList@)))
(if (wcmatch Text$ (strcat "*" Find$ "*"))
(progn
(setq ReplaceWith$ (FindReplace: Text$ Find$ Replace$))
(entmod (subst (cons 1 ReplaceWith$) (assoc 1 EntList@) EntList@))
(entupd EntName^)
);progn
);if
);progn
);if
(setq EntName^ (entnext EntName^))
);while
);progn
);if
(if (wcmatch Text$ (strcat "*" Find$ "*"))
(progn
(setq ReplaceWith$ (FindReplace: Text$ Find$ Replace$))
(entmod (subst (cons 1 ReplaceWith$) (assoc 1 EntList@) EntList@))
(entupd EntName^)
);progn
);if
);if
(setq Cnt# (1+ Cnt#))
);repeat
(command "UNDO" "END")
);progn
);if
);progn
);if
(princ)
);defun FindReplaceAll[ Moderator Action = ON ] What are [ CODE ] tags... (http://forums.augi.com/misc.php?do=bbcode#code) [ Moderator Action = OFF ]
sschwartz
2006-07-18, 02:50 PM
Wow! I can work with this... thank you so much! Great
BATx2
2006-10-26, 08:55 PM
I'm trying to do a similar task with a different font. I can get the command line version to work, but when I try to run it numerous times in a single lisp routine I get an unknown command error. How do you use this "in a program"?
Here's exactly what I'm trying to do:
convert "%%11" to "1/16"
convert "%%12" to "1/8"
convert "%%13" to "3/16"
... and so on to 7/8
It would also be helpful to know the best way to load findreplaceall so this routine can call it.
Thanks,
BATx2
sschwartz
2006-10-27, 04:06 PM
I'm trying to do a similar task with a different font. I can get the command line version to work, but when I try to run it numerous times in a single lisp routine I get an unknown command error. How do you use this "in a program"?
Here's exactly what I'm trying to do:
convert "%%11" to "1/16"
convert "%%12" to "1/8"
convert "%%13" to "3/16"
... and so on to 7/8
It would also be helpful to know the best way to load findreplaceall so this routine can call it.
Thanks,
BATx2
If you have the lisp routine, you need to appload it. (I suggest adding it to your startup suite). I am not 100% sure, but you may need to make one lisp for each find and replace.
Terry Cadd
2006-10-31, 12:04 AM
(load "FindReplaceAll");or place it in another startup loading file such as AcadDoc.lsp.
Create a similar function as follows that you will run on those drawings.
Load the new function from the command line i.e. (load "Replace"),
or better yet place it in another startup loading file such as AcadDoc.lsp.
Using APPLOAD is still another possibility to load these files.
(defun c:Replace ()
(FindReplaceAll "%%11" "1/16")
(FindReplaceAll "%%12" "1/8")
(FindReplaceAll "%%13" "3/16")
;etc.
(princ)
);defun
Merle.Hall
2006-12-13, 09:35 PM
Terry,
This works great unless you are (or in this case "I am") trying to replace path statements. It then thinks you need another double-quote mark and another end parenthesis, after which it simply fails.
(findreplaceall "\\server\path\path\dir\" "N:\dir")
...for example.
Merle
Terry,
This works great unless you are (or in this case "I am") trying to replace path statements. It then thinks you need another double-quote mark and another end parenthesis, after which it simply fails.
(findreplaceall "\\server\path\path\dir\" "N:\dir")
...for example.
Merle
Since this is in AutoLISP, add another slash "\" next to your current slash "\".
Merle.Hall
2006-12-13, 10:15 PM
I knew that! But I figured it would look for the exact string, not an interpreted one. Should have tried it anyway.
Thanks!
Merle
mymatrac
2009-09-09, 09:43 AM
Hi! Can you advice how to add multiline attributes to the processing by application (it is working only with single line attribute). Thank you
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.