vanhuyou Posted August 4, 2023 Posted August 4, 2023 I use the tcout command in autocad but it doesn't work with the mtext in the drawing. Please help me ! test.dwg Quote
Steven P Posted August 4, 2023 Posted August 4, 2023 I'm assuming you mean tcount, in the sample drawings the mtexts have fields in them, that might stop it working? Quote
SLW210 Posted August 4, 2023 Posted August 4, 2023 3 hours ago, Steven P said: I'm assuming you mean tcount, in the sample drawings the mtexts have fields in them, that might stop it working? Correct, it works fine in the supplied drawing with the fields converted to text. 1 Quote
vanhuyou Posted August 5, 2023 Author Posted August 5, 2023 (edited) 22 hours ago, Emmanuel Delay said: What result would you like? I need auto numbering all mtext, the result is the same as when using the tcout command. Help me. Edited August 5, 2023 by vanhuyou Quote
ketxu Posted August 5, 2023 Posted August 5, 2023 2 hours ago, vanhuyou said: I need auto numbering all mtext, the result is the same as when using the tcout command. Help me. Nhìn cái cách bạn post bản vẽ thì hời hợt, câu hỏi cũng hời hợt luôn, chán Quote
Steven P Posted August 5, 2023 Posted August 5, 2023 Might be better to post a new sample drawing showing what you had and then to one side what you want - a before and after Quote
vanhuyou Posted August 7, 2023 Author Posted August 7, 2023 (edited) On 8/5/2023 at 7:46 PM, Steven P said: Might be better to post a new sample drawing showing what you had and then to one side what you want - a before and after Sorry, i post drawing before and after use lisp. test.dwg Edited August 7, 2023 by vanhuyou Quote
Steven P Posted August 7, 2023 Posted August 7, 2023 The internet is usually your friend, and often there is something very close out there to use and make small changes: For example, a search "LISP prefix text" will give you the basics how to add a prefix to texts, you just need to read how to do sums in the LISP and convert the number to the string as a prefix. This example should work so long as the original author is OK with me messing with his code. Original code commented out with ';', my 4 lines of code is not indented. ;;MOdified from Mhupp here: ;;https://www.cadtutor.net/forum/topic/74-lisp-to-add-a-prefix-or-suffix-to-selected-text/ (defun C:ADDTXT (/ rep str *str ss txt sn vl e) (vl-load-com) ; (initget "Prefix Suffix") ; limit rep to Prefix or Suffix ; (setq rep ; (cond ; ((getkword "\nWhere to add Text [Prefix/Suffix]<Suffix>:")) ( "Suffix") ; get prefix or suffix ; ) ; ) ; end setq ; (or (setq *str (getenv "Insert-Text")) (setq *str "Here")) ; get any saved text from registery ; (if (= "" (setq str (getstring (strcat "\nEnter " rep " Text \"" *str "\": ")))) ; enter text to add ; (setq str *str) ; if enter pressed use registery text ; ) ; (setenv "Insert-Text" str) ; save new text to registery (setq str (getint "\nEnter start number (1): ")) ;;SP ADDED: Get the start number (if (= str nil)(setq str 1)) ;; If no start number then use 1 (setq ss (ssget "_:L" '((0 . "*TEXT")))) ; Select texts in order (foreach txt (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) ; loop through selected texts (setq vl (vlax-ename->vla-object txt)) ; get text entity as object (setq e (entget txt)) ; get text entity description ; (cond ; ((= rep "Prefix") ; (vla-put-textstring vl (strcat str (cdr (assoc 1 e)))) ; prefix text (vla-put-textstring vl (strcat "[" (itoa str) "]-" (cdr (assoc 1 e)))) ;; Add text as prefix (setq str (+ str 1)) ;; Increment counter, str ; ) ; ((= rep "Suffix") ; (vla-put-textstring vl (strcat (cdr (assoc 1 e)) str)) ; suffix text ; ) ; ) ) ; end for each (princ) ) Quote
SLW210 Posted August 7, 2023 Posted August 7, 2023 Have a look at Prefix/Suffix - add to numbers or text - AutoLISP, Visual LISP & DCL - AutoCAD Forums (cadtutor.net) There are also some Field to Text LISPs around or you can explode the MTEXT to TEXT to remove the Fields, that would let you use TCOUNT. Quote
vanhuyou Posted August 8, 2023 Author Posted August 8, 2023 16 hours ago, Steven P said: The internet is usually your friend, and often there is something very close out there to use and make small changes: For example, a search "LISP prefix text" will give you the basics how to add a prefix to texts, you just need to read how to do sums in the LISP and convert the number to the string as a prefix. This example should work so long as the original author is OK with me messing with his code. Original code commented out with ';', my 4 lines of code is not indented. ;;MOdified from Mhupp here: ;;https://www.cadtutor.net/forum/topic/74-lisp-to-add-a-prefix-or-suffix-to-selected-text/ (defun C:ADDTXT (/ rep str *str ss txt sn vl e) (vl-load-com) ; (initget "Prefix Suffix") ; limit rep to Prefix or Suffix ; (setq rep ; (cond ; ((getkword "\nWhere to add Text [Prefix/Suffix]<Suffix>:")) ( "Suffix") ; get prefix or suffix ; ) ; ) ; end setq ; (or (setq *str (getenv "Insert-Text")) (setq *str "Here")) ; get any saved text from registery ; (if (= "" (setq str (getstring (strcat "\nEnter " rep " Text \"" *str "\": ")))) ; enter text to add ; (setq str *str) ; if enter pressed use registery text ; ) ; (setenv "Insert-Text" str) ; save new text to registery (setq str (getint "\nEnter start number (1): ")) ;;SP ADDED: Get the start number (if (= str nil)(setq str 1)) ;; If no start number then use 1 (setq ss (ssget "_:L" '((0 . "*TEXT")))) ; Select texts in order (foreach txt (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) ; loop through selected texts (setq vl (vlax-ename->vla-object txt)) ; get text entity as object (setq e (entget txt)) ; get text entity description ; (cond ; ((= rep "Prefix") ; (vla-put-textstring vl (strcat str (cdr (assoc 1 e)))) ; prefix text (vla-put-textstring vl (strcat "[" (itoa str) "]-" (cdr (assoc 1 e)))) ;; Add text as prefix (setq str (+ str 1)) ;; Increment counter, str ; ) ; ((= rep "Suffix") ; (vla-put-textstring vl (strcat (cdr (assoc 1 e)) str)) ; suffix text ; ) ; ) ) ; end for each (princ) ) Perfect, thank so much man. 1 Quote
vanhuyou Posted August 8, 2023 Author Posted August 8, 2023 14 hours ago, SLW210 said: Have a look at Prefix/Suffix - add to numbers or text - AutoLISP, Visual LISP & DCL - AutoCAD Forums (cadtutor.net) There are also some Field to Text LISPs around or you can explode the MTEXT to TEXT to remove the Fields, that would let you use TCOUNT. Thank so much man. 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.