Jump to content

Recommended Posts

Posted

I use the tcout command in autocad but it doesn't work with the mtext in the drawing. Please help me !

 

test.dwg

Posted

What result would you like?

Posted

I'm assuming you mean tcount, in the sample drawings the mtexts have fields in them, that might stop it working?

Posted
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.

 

 

  • Like 1
Posted (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 by vanhuyou
Posted
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 :)

Posted

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

Posted (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 by vanhuyou
Posted

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)
)

 

Posted
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.

  • Like 1

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...