rsdonna Posted Friday at 05:39 PM Posted Friday at 05:39 PM I'm looking for a lisp that will allow me to do the exact same thing I do with TCOUNT but for multileaders. I have a drawing where I have mleaders going to many different lines and each has three lines of text. The first line has cable id and I want to be able to replace the last two characters of that line. In TCOUNT I would select each mtext object in order, have the count start at 1 and increase by 1 (1,1) and then I would have it find and replace the '0' I left at the end of each line with the sequential numbers created by TCOUNT. This is what I need to be able to do but on all the mleaders I have in this drawing. Anyone have something like this? Quote
devitg Posted Friday at 08:20 PM Posted Friday at 08:20 PM 2 hours ago, rsdonna said: I'm looking for a lisp that will allow me to do the exact same thing I do with TCOUNT but for multileaders. I have a drawing where I have mleaders going to many different lines and each has three lines of text. The first line has cable id and I want to be able to replace the last two characters of that line. In TCOUNT I would select each mtext object in order, have the count start at 1 and increase by 1 (1,1) and then I would have it find and replace the '0' I left at the end of each line with the sequential numbers created by TCOUNT. This is what I need to be able to do but on all the mleaders I have in this drawing. Anyone have something like this? @rsdonna, please upload your sample.dwg and the TCOUNT lisp Quote
rsdonna Posted Friday at 08:27 PM Author Posted Friday at 08:27 PM I don't have a TCOUNT lisp. TCOUNT is part of the express tools in AutoCAD. It's what I use when I'm going to renumber text or mtext. Unfortunately TCOUNT doesn't work in mleaders so I'm looking for a way to be able to do with mleaders what I do for text and mtext. Quote
devitg Posted Saturday at 11:31 AM Posted Saturday at 11:31 AM @rsdonna Ok , please upload your sample.dwg where you need to apply. Quote
rsdonna Posted Saturday at 12:03 PM Author Posted Saturday at 12:03 PM Sure, here is a sample of what I'll have in my drawings. In my drawings I'll have maybe 50 mleaders like these and I'm looking for a way to be able to pick them in order and then have it replace the -00 at the end with the sequential numbering. In TCOUNT I can pick what number I want it to start from and what the increment will be and then whether I want to overwrite, find and replace (which is what I need it to do), and also a prefix and a suffix option to place the text. Thanks for your help SAMPLE.dwg Quote
BIGAL Posted Saturday at 11:59 PM Posted Saturday at 11:59 PM (edited) Give this a try, also it replaces what ever is the last 2 characters. Call it version 1. ; https://www.cadtutor.net/forum/topic/98622-tcount-for-multileaders/ ; change mleader text add number on end. ; By alanH jultu 2025 (defun c:wow1 ( / num str newstr obj len) (setq num (getint "\nEnter 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 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))) ) (vlax-put obj 'textstring newstr) (setq num (1+ num)) ) (princ) ) Edited yesterday at 01:24 AM by BIGAL Quote
SLW210 Posted yesterday at 12:10 PM Posted yesterday at 12:10 PM Did you try the codes in the thread I posted? Quote
rsdonna Posted yesterday at 01:15 PM Author Posted yesterday at 01:15 PM 13 hours ago, BIGAL said: Give this a try, also it replaces what ever is the last 2 characters. Call it version 1. ; https://www.cadtutor.net/forum/topic/98622-tcount-for-multileaders/ ; change mleader text add number on end. ; By alanH jultu 2025 (defun c:wow1 ( / num str newstr obj len) (setq num (getint "\nEnter 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 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))) ) (vlax-put obj 'textstring newstr) (setq num (1+ num)) ) (princ) ) This is great. Is there a way to have it still do this if there are multiple lines of text in the mleader? I still have the wire name at the top line always but sometimes add 1 or 2 additional lines with other info about that wire. Thanks for your help. SAMPLE.dwg Quote
rsdonna Posted yesterday at 01:17 PM Author Posted yesterday at 01:17 PM 1 hour ago, SLW210 said: Did you try the codes in the thread I posted? I did. I had found it before and it is great just doesn't do exactly what i need. I can use it to add the numbering at the end but if I need to renumber then it won't work the way I need it to. Thank you for this. Quote
BIGAL Posted 18 hours ago Posted 18 hours ago (edited) 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) ) Edited 17 hours ago by BIGAL Quote
SLW210 Posted 7 hours ago Posted 7 hours ago 20 hours ago, rsdonna said: I did. I had found it before and it is great just doesn't do exactly what i need. I can use it to add the numbering at the end but if I need to renumber then it won't work the way I need it to. Thank you for this. I linked several LISPs in that thread, which ones did you try? Quote
rsdonna Posted 5 hours ago Author Posted 5 hours ago 1 hour ago, SLW210 said: I linked several LISPs in that thread, which ones did you try? I tried CopyText and MTMTMLT. I found CopyText great as it is something that I will end up using quite a bit since I have to copy text to multiple mleaders sometimes, but neither of the ones I tried did what I was looking for unfortunately. MTMTMLT only adds the sequential numbering at the end and doesn't let me replace what I have in the text as a place holder. What I need replaced is always at the end of the first line and since I have multiple lines of text sometimes it doesn't work with the numbering being added at the end of all the text Quote
SLW210 Posted 3 hours ago Posted 3 hours ago There was a link to a LISP at Autodesk forums as well. I have a few versions of my LISP as mentioned in that thread, I'll think about updating and altering one if I get time. I need a clearly explained before and after .dwg, just go through what you do in TCOUNT, better yet show it with TCOUNT on MText as well, even with your drawings as MText, I followed the steps you gave in your first post and do not get the results you ask for. Quote
SLW210 Posted 2 hours ago Posted 2 hours ago 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 as Prefix, Suffix or Find and Replace. *| ;;; *| ;;; https://www.cadtutor.net/forum/topic/98622-tcount-for-multileaders/#findComment-675446 *| ;;; *| ;;; 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/28/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:TMTMS () (c:TxtMTxtMldrSeq)) ; shortcut (defun c:TxtMTxtMldrSeq (/ ss ent en_obj current_text new_text num prefix suffix numType i entType findStr replaceStr lineNum lineNumStr lineList newLines ) ;; Prompt for prefix and suffix (setq prefix (getstring "\nEnter prefix text (or leave blank): ")) (setq suffix (getstring "\nEnter suffix text (or leave blank): ")) ;; Prompt for numbering type (setq numType (strcase (getstring "\nEnter 'P' for Prefix, 'S' for Suffix, or 'N' for No modification: " ) ) ) (if (not (member numType '("P" "S" "N"))) (progn (princ "\nInvalid choice. Exiting.") (exit)) ) ;; Find and Replace (setq findStr (getstring T "\nEnter FIND text (or press Enter to skip): ") ) (setq replaceStr (if (/= findStr "") (getstring T "\nEnter REPLACE text: ") "" ) ) ;; 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 found.") (exit)) ) ;; Loop through entities (setq i 0) (repeat (sslength ss) (setq ent (ssname ss i)) (setq en_obj (vlax-ename->vla-object ent)) (setq entType (cdr (assoc 0 (entget ent)))) (setq current_text (vla-get-TextString en_obj)) (setq num (itoa (1+ i))) ;; Find & replace (if (and (/= findStr "") (/= replaceStr "")) (setq current_text (vl-string-subst replaceStr findStr current_text) ) ) (cond ;; TEXT ((= entType "TEXT") (setq new_text (cond ((= numType "P") (strcat prefix num " " current_text)) ((= numType "S") (strcat current_text " " suffix num)) ((= numType "N") current_text) ) ) (vla-put-TextString en_obj new_text) ) ;; MTEXT or MULTILEADER ((or (= entType "MTEXT") (= entType "MULTILEADER")) (setq lineList (split-text-lines current_text)) (setq newLines (if (and lineNum (> lineNum 0) (<= lineNum (length lineList))) ;; Modify specific line (mapcar '(lambda (line idx) (if (= idx (1- lineNum)) (cond ((= numType "P") (strcat prefix num " " line)) ((= numType "S") (strcat line " " suffix num)) ((= numType "N") line) ) line ) ) lineList (number-seq 0 (1- (length lineList))) ) ;; Modify all lines (mapcar '(lambda (line) (cond ((= numType "P") (strcat prefix num " " line)) ((= numType "S") (strcat line " " suffix num)) ((= numType "N") line) ) ) lineList ) ) ) ;; Combine lines (setq new_text (apply 'strcat (mapcar '(lambda (l) (strcat l "\\P")) newLines) ) ) (vla-put-TextString en_obj new_text) ) ) (setq i (1+ i)) ) (princ "\nModifications completed.") (princ) ) ;; Split text into lines (MTEXT line delimiter = \P) (defun split-text-lines (txt) (vl-remove-if 'null (parse txt "\\P")) ) ;; Parse string by delimiter (defun parse (str delim / result pos start) (setq start 1) (while (setq pos (vl-string-search delim str (1- start))) (setq result (cons (substr str start (- pos start)) result)) (setq start (+ pos (strlen delim) 1)) ) (reverse (cons (substr str start) result)) ) ;; Create list of numbers from start to end (defun number-seq (start end) (if (> start end) nil (cons start (number-seq (1+ start) end)) ) ) I left the options from the other LISP, due to time, if you want or I get more time, I might remove the other options. Quote
rsdonna Posted 1 hour ago Author Posted 1 hour ago 1 hour ago, 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 as Prefix, Suffix or Find and Replace. *| ;;; *| ;;; https://www.cadtutor.net/forum/topic/98622-tcount-for-multileaders/#findComment-675446 *| ;;; *| ;;; 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/28/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:TMTMS () (c:TxtMTxtMldrSeq)) ; shortcut (defun c:TxtMTxtMldrSeq (/ ss ent en_obj current_text new_text num prefix suffix numType i entType findStr replaceStr lineNum lineNumStr lineList newLines ) ;; Prompt for prefix and suffix (setq prefix (getstring "\nEnter prefix text (or leave blank): ")) (setq suffix (getstring "\nEnter suffix text (or leave blank): ")) ;; Prompt for numbering type (setq numType (strcase (getstring "\nEnter 'P' for Prefix, 'S' for Suffix, or 'N' for No modification: " ) ) ) (if (not (member numType '("P" "S" "N"))) (progn (princ "\nInvalid choice. Exiting.") (exit)) ) ;; Find and Replace (setq findStr (getstring T "\nEnter FIND text (or press Enter to skip): ") ) (setq replaceStr (if (/= findStr "") (getstring T "\nEnter REPLACE text: ") "" ) ) ;; 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 found.") (exit)) ) ;; Loop through entities (setq i 0) (repeat (sslength ss) (setq ent (ssname ss i)) (setq en_obj (vlax-ename->vla-object ent)) (setq entType (cdr (assoc 0 (entget ent)))) (setq current_text (vla-get-TextString en_obj)) (setq num (itoa (1+ i))) ;; Find & replace (if (and (/= findStr "") (/= replaceStr "")) (setq current_text (vl-string-subst replaceStr findStr current_text) ) ) (cond ;; TEXT ((= entType "TEXT") (setq new_text (cond ((= numType "P") (strcat prefix num " " current_text)) ((= numType "S") (strcat current_text " " suffix num)) ((= numType "N") current_text) ) ) (vla-put-TextString en_obj new_text) ) ;; MTEXT or MULTILEADER ((or (= entType "MTEXT") (= entType "MULTILEADER")) (setq lineList (split-text-lines current_text)) (setq newLines (if (and lineNum (> lineNum 0) (<= lineNum (length lineList))) ;; Modify specific line (mapcar '(lambda (line idx) (if (= idx (1- lineNum)) (cond ((= numType "P") (strcat prefix num " " line)) ((= numType "S") (strcat line " " suffix num)) ((= numType "N") line) ) line ) ) lineList (number-seq 0 (1- (length lineList))) ) ;; Modify all lines (mapcar '(lambda (line) (cond ((= numType "P") (strcat prefix num " " line)) ((= numType "S") (strcat line " " suffix num)) ((= numType "N") line) ) ) lineList ) ) ) ;; Combine lines (setq new_text (apply 'strcat (mapcar '(lambda (l) (strcat l "\\P")) newLines) ) ) (vla-put-TextString en_obj new_text) ) ) (setq i (1+ i)) ) (princ "\nModifications completed.") (princ) ) ;; Split text into lines (MTEXT line delimiter = \P) (defun split-text-lines (txt) (vl-remove-if 'null (parse txt "\\P")) ) ;; Parse string by delimiter (defun parse (str delim / result pos start) (setq start 1) (while (setq pos (vl-string-search delim str (1- start))) (setq result (cons (substr str start (- pos start)) result)) (setq start (+ pos (strlen delim) 1)) ) (reverse (cons (substr str start) result)) ) ;; Create list of numbers from start to end (defun number-seq (start end) (if (> start end) nil (cons start (number-seq (1+ start) end)) ) ) I left the options from the other LISP, due to time, if you want or I get more time, I might remove the other options. I gave this a try and I don't know if maybe I'm doing something wrong but it gave me something weird. It changed the end of the 1st line but it just gave me 0's instead of renumbering and then on the two middle mleaders it removed the "D" at the end of strand. Thanks for your help with this, really appreciate it! 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.