@mmprakash90 wrote:
The above objects are constant, ....
If "constant" means really constant, that is, the source Text is always six and only six numerical-only digits, and the target object always ends with six capital X's, whether or not there is anything more before them or how much is before them, and if they're both Text objects specifically, then this seems to work:
(defun C:TEST (/ source str1 target str2)
(if
(and
(setq source (car (entsel "\nNumerical source Text object: ")))
(wcmatch (setq str1 (getpropertyvalue source "TextString")) "*######")
(not (redraw source 3)); highlight [(not) because it returns nil]
(setq target (car (entsel "\nText object with XXXXXX to be replaced: ")))
(wcmatch (setq str2 (getpropertyvalue target "TextString")) "*XXXXXX")
); and
(progn ; then
(redraw source 4); un-highlight
(setpropertyvalue target "TextString" (vl-string-subst str1 "XXXXXX" str2))
); progn
(prompt "\nInappropriate object selected.")
); if
(prin1)
)
But that's in simplest terms. It could be made more sophisticated, to overcome certain possibilities. For example, it could be made to allow for Mtext [different property name for the contents]. If a target ends with more than six capital X's in a row, the first six of them will be the ones replaced, not the last six. It currently allows selection of Text on locked Layers, but could prevent that at least for the target [it wouldn't matter for the source, unless you want that removed]. And probably some other things....
Kent Cooper, AIA