Hi, I know there is old question before similar to this( Pre-defined find & replace lisp) but it does not work with me
i need lisp that replace list of my pre-defind letter
like for example
the lisp will find "m" letter and will replace it automatically without asking me with letter "F"
"t" with "s"
and then i will need to continue my list if there is new items.
Waiting Expert,
@shehab10 wrote:
I want to execute lisp command pre-loaded automatically with default setting of his dialogue called Batch Find & Replace of Lee Mac (http://www.lee-mac.com/bfind.html) after finishing all procedures as extra step.Is it possible ?
The GUI configuration file & text file containing any stored search items for my Batch Find & Replace Text program can be found by typing the following at the AutoCAD command-line:
(findfile "LMAC_BFind_V2-0.cfg")
The above will return the filepath to the GUI configuration file - this is usually saved to the ROAMABLEROOTPREFIX directory.
It is not possible to bypass the program dialog as I have not written a command-line version of the program, and, since AutoLISP does not permit multiple processor threads, you cannot autonomously operate the dialog from a separate AutoLISP program or macro without user input.
Ok i did two backslashes it works but here is problem it replace only one item ( i mean if i have Mtext and there is paragraph that include multiple "[h" it will replace only one item to replace another one i have to click command test again.
I attached the picture to clarify and this last code used.
so there must be way that replace all items of "[h" assuming that it will become in my second replacement ?
(defun c:test (/ I L NEW-LST NTXT OBJ OLD-LST OTXT SS) (vl-load-com) (if (setq ss (ssget "x" '((0 . "*TEXT") (1 . "*")))) (progn (setq i (sslength ss)) (setq old-lst '("Kd" "jl" "[h")) (setq new-lst '("kd" "jL" "\\{h")) (while (not (minusp (setq i (1- i)))) (setq obj (vlax-ename->vla-object (ssname ss i))) (setq otxt (vlax-get-property obj 'TextString)) (setq ntxt (vl-string-translate "mt" "Fs" otxt)) (vlax-put-property obj 'TextString ntxt) (vlax-put-property obj 'StyleName "Standard") (setq otxt (vlax-get-property obj 'TextString)) (setq l (length old-lst)) (while (not (minusp (setq l (1- l)))) (if (vl-string-search (nth l old-lst) otxt) (vlax-put-property obj 'TextString (vl-string-subst (nth l new-lst) (nth l old-lst) otxt)) );; if );; while );; while );; progn );; if (princ) );; test
shehab10,
for more than one instance in a text string, we need to create a loop to replace all instances.
Using your exemple, maybe something like this
(defun c:test (/ I L NEW-LST MTX-LST NTXT OBJ OLD-LST OTXT SS TYP) (vl-load-com) (if (setq ss (ssget "x" '((0 . "TEXT,MTEXT") (1 . "*")))) (progn (setq i (sslength ss)) (setq old-lst '("Kd" "jl" "[h")) (setq new-lst '("kd" "jL" "\\{h")) (setq mtx-lst '("kd" "jL" "\\\\\\{h")) (while (not (minusp (setq i (1- i)))) (setq obj (vlax-ename->vla-object (ssname ss i))) (setq otxt (vlax-get-property obj 'TextString)) (setq ntxt (vl-string-translate "mt" "Fs" otxt)) (vlax-put-property obj 'TextString ntxt) (vlax-put-property obj 'StyleName "Standard") (setq otxt (vlax-get-property obj 'TextString)) (setq typ (vlax-get-property obj 'ObjectName)) (if (equal typ "AcDbText") (progn (setq l (length old-lst)) (while (not (minusp (setq l (1- l)))) (while (vl-string-search (nth l old-lst) otxt) (setq otxt (vl-string-subst (nth l new-lst) (nth l old-lst) otxt)) );; while (vlax-put-property obj 'TextString otxt) );; while );; progn );; if (if (equal typ "AcDbMText") (progn (setq l (length old-lst)) (while (not (minusp (setq l (1- l)))) (while (vl-string-search (nth l old-lst) otxt) (setq otxt (vl-string-subst (nth l mtx-lst) (nth l old-lst) otxt)) );; while (vlax-put-property obj 'TextString otxt) );; while );; progn );; if );; while );; progn );; if (princ) );; test
But you have to keep in mind, that some symbols in MTEXT, are used for string formatting,
i.e.
\P => paragraph
{\\fArial|b1|i0|c0|p34;aa => the text is arial and b1 means that it is bold
\\fArial|b0|i1|c0|p34;aa">\\fArial|b0|i1|c0|p34;aa} => the text is arial and i1 means that it is italic
and so on...
So, there is no simple way to deal with MTEXT...
Henrique
Good but i have many entry in my list so when i select multiple objects to replace the autocad is hanging,
Is there a way that autocad lisp did not inspect(search) every element(letter) to compare with its counterpart
for replace procedure unless the letters on the current drawing or the one is being selected by window (kind of speeding up the search and avoid long time comparing letter by letter to reach result more quick) ?
I think there must be way of control.
look of example my list and there are more coming !
....
(progn
(setq i (sslength ss))
(setq old-lst '("Fh" "FF" "FJ" "FE" "F[" "FP" "FO" "FJ" "F]" "F`" "Fv" "F>" "FS" "FA" "FW" "FQ" "F'"
"F/" "[h"))
(setq new-lst '("fh" "fF" "fJ" "fE" "f\\{" "fP" "fO" "fJ" "f]" "f`" "fv" "f>" "fS" "fA" "fW" "FQ" "f'"
"f/" "\\{h"))
(setq mtx-lst '("kd" "fF" "fJ" "fE" "f\\{" "fP" "fO" "fJ" "f]" "f`" "fv" "f>" "fS" "fA" "fW" "FQ" "f'"
"f/" "\\{h"))
(while (not (minusp (setq i (1- i))))
...
Could we have a line of code that convert predefined specific text styles like ("Arial", "Arial_1","Arial_2" ) i have in the drawing to "Standard" instead of selection or entire drawing ?
I have pre defind text style in my drawing called Arial_1, Arial_2 ,Arial_3
I want this pre defind text style to be converted to Standard as it is in the code.
One more thing is /P is //P in the code ? can i make /P fixed as casse match and not be capable to be replaced?
@shehab10 wrote:
...
One more thing is /P is //P in the code ? can i make /P fixed as casse match and not be capable to be replaced?
If I understood correctly...
from the VisualLISP Console:
_$ (cdr (assoc 1 (entget (car (entsel)))))
"hhh/Phhh"
"/P" is "/P", if you don't want to replace it, don't include it in any list.
Henrique
@hmsilva wrote:If I understood correctly...
from the VisualLISP Console:_$ (cdr (assoc 1 (entget (car (entsel)))))
"hhh/Phhh"
Is the above the code for converting the text style into standard ? where should i put it ?
"/P" is indication for paragraph , i have in my replacement list P but the paragraph is being corrupted because /P is being /p .
@shehab10 wrote:
@hmsilva wrote:If I understood correctly...
from the VisualLISP Console:_$ (cdr (assoc 1 (entget (car (entsel)))))
"hhh/Phhh"
Is the above the code for converting the text style into standard ? where should i put it ?
"/P" is indication for paragraph , i have in my replacement list P but the paragraph is being corrupted because /P is being /p .
with the above code, you can select a text/mtext entity and will return the text string...
to change the style is
(vlax-put-property obj 'StyleName "Standard")
and is already on the code...
"\P" is paragraph...
Post the code you have so far.
Henrique
The code so far
the addition i wish is to be able to convert pre-defined text style like Arial_1,Arial_2 to "standard" ,instead of getting all text styles to convert to standard.
(defun c:test (/ I L NEW-LST MTX-LST NTXT OBJ OLD-LST OTXT SS TYP) (vl-load-com) (if (setq ss (ssget "x" '((0 . "TEXT,MTEXT") (1 . "*")))) (progn (setq i (sslength ss)) (setq old-lst '("Kd" "jl" "[h" "\Ph")) (setq new-lst '("kd" "jL" "\\{h" "\ph")) (setq mtx-lst '("kd" "jL" "\\\\\\{h" "\ph")) (while (not (minusp (setq i (1- i)))) (setq obj (vlax-ename->vla-object (ssname ss i))) (setq otxt (vlax-get-property obj 'TextString)) (setq ntxt (vl-string-translate "mt" "Fs" otxt)) (vlax-put-property obj 'TextString ntxt) (vlax-put-property obj 'StyleName "Standard") (setq otxt (vlax-get-property obj 'TextString)) (setq typ (vlax-get-property obj 'ObjectName)) (if (equal typ "AcDbText") (progn (setq l (length old-lst)) (while (not (minusp (setq l (1- l)))) (while (vl-string-search (nth l old-lst) otxt) (setq otxt (vl-string-subst (nth l new-lst) (nth l old-lst) otxt)) );; while (vlax-put-property obj 'TextString otxt) );; while );; progn );; if (if (equal typ "AcDbMText") (progn (setq l (length old-lst)) (while (not (minusp (setq l (1- l)))) (while (vl-string-search (nth l old-lst) otxt) (setq otxt (vl-string-subst (nth l mtx-lst) (nth l old-lst) otxt)) );; while (vlax-put-property obj 'TextString otxt) );; while );; progn );; if );; while );; progn );; if (princ) );; test
Cheers
(defun c:test (/ I L NEW-LST MTX-LST NTXT OBJ OLD-LST OTXT SS TYP) (vl-load-com) (if (setq ss (ssget "x" '((0 . "TEXT,MTEXT") (1 . "*")))) (progn (setq i (sslength ss)) (setq old-lst '("Kd" "jl" "[h" "\Ph")) (setq new-lst '("kd" "jL" "\\{h" "\ph")) (setq mtx-lst '("kd" "jL" "\\\\\\{h" "\ph")) (while (not (minusp (setq i (1- i)))) (setq obj (vlax-ename->vla-object (ssname ss i))) (setq otxt (vlax-get-property obj 'TextString)) (setq ntxt (vl-string-translate "mt" "Fs" otxt)) (vlax-put-property obj 'TextString ntxt) (if (wcmatch (vlax-get-property obj 'StyleName) "Arial_1,Arial_2") (vlax-put-property obj 'StyleName "Standard")) (setq otxt (vlax-get-property obj 'TextString)) (setq typ (vlax-get-property obj 'ObjectName)) (if (equal typ "AcDbText") (progn (setq l (length old-lst)) (while (not (minusp (setq l (1- l)))) (while (vl-string-search (nth l old-lst) otxt) (setq otxt (vl-string-subst (nth l new-lst) (nth l old-lst) otxt)) );; while (vlax-put-property obj 'TextString otxt) );; while );; progn );; if (if (equal typ "AcDbMText") (progn (setq l (length old-lst)) (while (not (minusp (setq l (1- l)))) (while (vl-string-search (nth l old-lst) otxt) (setq otxt (vl-string-subst (nth l mtx-lst) (nth l old-lst) otxt)) );; while (vlax-put-property obj 'TextString otxt) );; while );; progn );; if );; while );; progn );; if (princ) );; test
Henrique
Assuming that Arial_1,Arial_2 style will only be converted by both 1st replacement,2nd replacement
the rest of text styles like ex:Arial_5,Times new tomans should not be replaced by first and second .
but what is happenning now the rest is being replaced by first could i make it not be replaced by first ?
could i know please the extra line code that you provide for limiting text styles replacement because i will make its usage as optional?
Thank you for your help,
if I understood correctly, change
(if (setq ss (ssget "x" '((0 . "TEXT,MTEXT") (1 . "*"))))
to
(if (setq ss (ssget "x" '((0 . "TEXT,MTEXT") (7 . "Arial_1,Arial_2"))))
the "Arial_1,Arial_2" at the ssget filter, will be text styles to be selected...
Henrique
Good i think it works now thanks, so do you agree that there is no need now for this below code if i added above the new one.
(if (wcmatch (vlax-get-property obj 'StyleName) "Arial_1,Arial_2")
is this code applicable to be executed on multiple drawings,layouts once (ex : same folder path or sub path which the path will be pre defined in the code) ?
if it is difficult or impossible no problem just curious to know if it is possible ?
Thanks for this nice developed code.
@shehab10 wrote:Good i think it works now thanks, so do you agree that there is no need now for this below code if i added above the new one.
(if (wcmatch (vlax-get-property obj 'StyleName) "Arial_1,Arial_2")
Correct!
@shehab10 wrote:is this code applicable to be executed on multiple drawings,layouts once (ex : same folder path or sub path which the path will be pre defined in the code) ?
if it is difficult or impossible no problem just curious to know if it is possible ?
Is possible, but using a script file and, for example, ScriptPro, from Autodesk (its free)
@shehab10 wrote:
Thanks for this nice developed code.
You're welcome, shehab10
Henrique
Something i noticed that i may need a line of code (addition) to re justify text style inside the code from top left to Left in the new text style "standard" because the replacement will shrink letters.