Code Red > AutoLISP (Vanilla / Visual)
Command line Find
SPDCad:
Does the 'Find' command have a command line prompt or is it dialog box controlled only?
I am writting a lisp and I would like to use find and replace in the lisp, but I can't call it up without bringing up the dialog box.
If it is not possible to control the find and replace command at the command prompt, does any one have code that will find and replace a string item in mtext, text and attribute format? I know I have a few long retired programme that do, but I am at work and I don't have access to the code.
:O(
Any help would be greatly appreciated.
Damn! I need to carry my all my lisp programmes (rerired or not) around with me on a DVD! :?
CADaver:
Older than dirt, but still works on TEXT MTEXT and DIMS
--- Code: ---;;; a rudimentary text editor Frank Emerick, RBCulp
(defun c:cx () (c:chgtext))
(defun C:CHGTEXT () (cht_Edit nil))
(defun cht_Edit (objs / last_o tot_o ent o_str n_str st s_temp
n_slen o_slen si chf chm cont ans class)
(command "undo" "BEGIN")
(if (null objs)
(setq objs (ssget))
)
(setq chm 0)
(if objs
(progn ;; If any objects selected
(if (= (type objs) 'ENAME)
(progn
(setq ent (entget objs))
(princ (strcat "\nExisting string: " (cdr (assoc 1 ent))))
)
(if (= (sslength objs) 1)
(progn
(setq ent (entget (ssname objs 0)))
(princ (strcat "\nExisting string: " (cdr (assoc 1 ent))))
)
)
)
(setq o_str (getstring "\nMatch string : " t))
(setq o_slen (strlen o_str))
(if (/= o_slen 0)
(progn
(setq n_str (getstring "\nNew string : " t))
(setq n_slen (strlen n_str))
(setq last_o 0
tot_o (if (= (type objs) 'ENAME)
1
(sslength objs)
)
)
;; For each selected object...
(while (< last_o tot_o)
(setq class (cdr (assoc 0 (setq ent (entget (ssname objs last_o))))))
(if (cond (= "TEXT" class)
(= "mtext" class)
(= "DIMENSION" class) )
(progn
(setq chf nil si 1)
(setq s_temp (cdr (assoc 1 ent)))
(while (= o_slen (strlen (setq st (substr s_temp si o_slen))))
(if (= st o_str)
(progn
(setq s_temp (strcat
(if (> si 1)
(substr s_temp 1 (1- si))
""
)
n_str
(substr s_temp (+ si o_slen))
)
)
(setq chf t) ;; Found old string
(setq si (+ si n_slen))
)
(setq si (1+ si))
)
)
(if chf
(progn ;; Substitute new string for old
;; Modify the TEXT entity
(entmod (subst (cons 1 s_temp) (assoc 1 ent) ent))
(setq chm (1+ chm))
)
)
)
)
(setq last_o (1+ last_o))
)
)
;; else go on to the next line...
)
)
)
(if (/= (type objs) 'ENAME)
;; Print total lines changed
(if (/= (sslength objs) 1)
(princ (strcat (rtos chm 2 0) " text lines changed."))
(terpri)
)
)
(command "undo" "END")
(terpri)
)
--- End code ---
SPDCad:
Thanks CADaver! :)
CADaver:
--- Quote from: SPDCad ---Thanks CADaver! :)
--- End quote ---
You're welcome. Bear in mind that it was originally written nearly 18 years ago and has been "tweaked" a bit since. (I think there may be newer/netter versions floating around somewhere.)
I am quite sure the "real" gurus here can come up with something considerably more elegant.
Sitra:
What about something where you can open up a drawing and it will do a find and replace with preset words to look for and replace. Is this possible.
Navigation
[0] Message Index
[#] Next page
Go to full version