rsdonna Posted yesterday at 12:20 PM Author Posted yesterday at 12:20 PM On 7/27/2025 at 7:35 PM, BIGAL said: I guess look for newline then work backwards two characters. Try this. (defun c:wow ( / num str str1 str2 newstr obj len ) (setq num (getint "\nEnetr start number ")) (while (setq ent (entsel "\nPick Mleader - Enter to stop. ")) (setq obj (vlax-ename->vla-object (car ent))) (setq str (vlax-get obj 'textstring)) (setq pos (vl-string-position 92 str)) (if (= pos nil) (progn (setq len (strlen str)) (if (< num 10) (setq newstr (strcat (substr str 1 (- len 2)) "0" (rtos num 2 0))) (setq newstr (strcat (substr str 1 (- len 2)) (rtos num 2 0))) ) ) (progn (if (< num 10) (setq newstr (strcat "0" (rtos num 2 0))) (setq newstr (rtos num 2 0)) ) (setq str1 (strcat (substr str 1 (- pos 2)) newstr)) (setq str2 (substr str (+ pos 1))) (setq newstr (strcat str1 str2)) ) ) (vlax-put obj 'textstring newstr) (setq num (1+ num)) ) (princ) ) Yes this works great!! Thanks so much. You Rock! Quote
rsdonna Posted yesterday at 12:21 PM Author Posted yesterday at 12:21 PM 23 hours ago, SLW210 said: Works for me here as well. This worked for me as well. Quote
rsdonna Posted yesterday at 12:26 PM Author Posted yesterday at 12:26 PM 23 hours ago, SLW210 said: I placed a new LISP in my earlier post to just do a Sequential Find and Replace, see if that works for you. I am working on a bigger LISP with dialog box input and select the options, but that's going to be a while due to my workload. I will try that one out as well. Haven't been able to get back on here too often to try everything out because of my workload as well. I would be very interested to see the LISP with the dialog box as well. Thanks for all your help. Quote
rsdonna Posted yesterday at 12:36 PM Author Posted yesterday at 12:36 PM On 7/28/2025 at 11:38 AM, SLW210 said: You got lucky, stopped at work waiting on more information. I lightly tested this on your drawings. ;;; Sequential Numbering added to MLeader, Mtext and Text with Find and Replace. *| ;;; *| ;;; https://www.cadtutor.net/forum/topic/26420-tcount-in-a-multileader/#comment-648519 *| ;;; *| ;;; With help from: https://forums.augi.com/showthread.php?117315-Modify-text-in-multileader *| ;;; *| ;;; By SLW210 (Steve Wilson) *| ;;; *| ;;; No guarantees use at your own risk *| ;;; *| ;;; Original 07/29/2025 *| ;;; *| ;;; *| ;;; Thanks most to AlanJT, lpseifert and irneb (Where have y'all gone?) *| ;;; *| ;;;************************************************************************************************| ;;;************************************************************************************************| ;;; When asked for FIND/REPLACE, leave blank to skip. *| ;;; *| ;;; For MTEXT/MLEADER, enter All to apply the change to all lines, or specify a line number. *| ;;; *| ;;;************************************************************************************************| ;;;************************************************************************************************| (vl-load-com) (defun c:FnRSeq () (c:FindReplaceLineSeq)) ; Shortcut command (defun c:FindReplaceLineSeq (/ ss ent en_obj current_text entType findStr replaceBase lineNum lineNumStr lineList newLines idx replNum newVal i ) ;; Prompt for find text (setq findStr (getstring T "\nEnter FIND text: ")) (if (= findStr "") (progn (princ "\nFIND string cannot be empty.") (exit)) ) ;; Starting replacement number (setq replaceBase (getstring T "\nEnter starting REPLACE number (e.g. 01): " ) ) (if (not (numberp (read replaceBase))) (progn (princ "\nInvalid number. Exiting.") (exit)) ) ;; Prompt for line number (initget 1 "All") (setq lineNumStr (getstring "\nEnter line number for MTEXT/Multileader (or type 'All'): " ) ) (setq lineNum (if (wcmatch (strcase lineNumStr) "ALL") nil (atoi lineNumStr) ) ) ;; Get selection set (setq ss (ssget '((0 . "TEXT,MTEXT,MULTILEADER")))) (if (not ss) (progn (princ "\nNo valid text entities selected.") (exit)) ) ;; Initialize replacement counter (setq replNum (atoi replaceBase)) (setq idx 0) ;; Process each selected entity (repeat (sslength ss) (setq ent (ssname ss idx)) (setq en_obj (vlax-ename->vla-object ent)) (setq entType (cdr (assoc 0 (entget ent)))) (setq current_text (vla-get-TextString en_obj)) (setq newVal (strcat (substr "0000000000" 1 (- (strlen replaceBase) (strlen (itoa replNum))) ) (itoa replNum) ) ) ;; Process by entity type (cond ;; Plain TEXT ((= entType "TEXT") (vla-put-TextString en_obj (vl-string-subst newVal findStr current_text) ) ) ;; MTEXT or MULTILEADER ((or (= entType "MTEXT") (= entType "MULTILEADER")) (setq lineList (split-text-lines current_text)) (setq i -1) (setq newLines (mapcar (function (lambda (line) (setq i (1+ i)) (if (or (null lineNum) (= i (1- lineNum))) (vl-string-subst newVal findStr line) line ) ) ) lineList ) ) (vla-put-TextString en_obj (join-lines newLines "\\P")) ) ) ;; Increment counter and index (setq replNum (1+ replNum)) (setq idx (1+ idx)) ) (princ "\nSequential find & replace completed.") (princ) ) ;;;*************************| ;;; Functions | ;;;*************************| (defun split-text-lines (txt) (vl-remove-if 'null (parse txt "\\P")) ) (defun parse (str delim / result pos start) (setq start 1 result '() ) (while (setq pos (vl-string-search delim str (1- start))) (setq result (cons (substr str start (- pos start -1)) result)) (setq start (+ pos (strlen delim) 1)) ) (reverse (cons (substr str start) result)) ) (defun join-lines (lst sep) (if (null lst) "" (apply 'strcat (cons (car lst) (mapcar (function (lambda (s) (strcat sep s))) (cdr lst)) ) ) ) ) This LISP just does a Find and Replace Sequentially no Prefix/Suffix. Tried this one and think I'm doing it correctly but am getting a weird outcome. I enter 03 to be the text to find and 01 the text to replace it with and it numbered them sequentially but placed a space between the 0 and 1. Also I tried it again but put 08 as the replace text and it gave me the same this as if I had put 01 for the replace text. Quote
SLW210 Posted 18 hours ago Posted 18 hours ago Works fine on your drawing here. Post that drawing if possible, looks like something in the Mleader MText. Post the command line as well. Command: FNRSEQ Enter FIND text: 03 Enter starting REPLACE number (e.g. 01): 01 Enter line number for MTEXT/Multileader (or type 'All'): 1 Select objects: 1 found Select objects: 1 found, 2 total Select objects: Specify opposite corner: 0 found Select objects: 1 found, 3 total Select objects: 1 found, 4 total Select objects: Sequential find & replace completed. Quote
rsdonna Posted 1 hour ago Author Posted 1 hour ago 17 hours ago, SLW210 said: Works fine on your drawing here. Post that drawing if possible, looks like something in the Mleader MText. Post the command line as well. Command: FNRSEQ Enter FIND text: 03 Enter starting REPLACE number (e.g. 01): 01 Enter line number for MTEXT/Multileader (or type 'All'): 1 Select objects: 1 found Select objects: 1 found, 2 total Select objects: Specify opposite corner: 0 found Select objects: 1 found, 3 total Select objects: 1 found, 4 total Select objects: Sequential find & replace completed. After seeing your post I realized I was trying it with the wrong LISP. I was trying it with TMTMS and that was giving me the results that had the space and wasn't numbering anything. Just tried it with this one 'FNRSEQ' and it works perfectly. Thank you so much for this. Quote
SLW210 Posted 3 minutes ago Posted 3 minutes ago Yes, that had some issues, I think I have that sorted, but not ready to repost. Still working on adding the DCL to it. It happens to me all of the time. No worries! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.